How to display the parent category as selected in django template?

Here I am trying to update category model but I got problem while displaying the already selected parent category in the template. Update works fine.

what I want here is if the category A has parent B then in the edit template B should be displayed as selected parent otherwise there should be option to select one category as a parent from the dropdown list.

models

class Category(models.Model):
    parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.SET_NULL)
    slug = models.SlugField(unique=True, max_length=50)
    title = models.CharField(max_length=255, unique=True)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

views

class EditCategoryView(generic.UpdateView, SuccessMessageMixin):
    model = Category
    form_class = CreateCategoryForm
    template_name = 'edit_category.html'
    success_url = reverse_lazy('list_categories')
    slug_url_kwarg = 'slug'
    success_message = 'Updated Successfully.'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['categories'] = Category.objects.all()
        return context

templates

 <label for="select" class="">Category Parent</label>
                    <select name="parent" id="exampleSelect"
                  class="form-control">
                     <option selected value="">Select</option>
                    {% for category in categories %}
                         {% if object.parent_id == category.parent_id %}
                   <option value="{{object.parent_id}}" selected>{{category.parent.title}} </option>
                        {% else %}
                        <option value="{{category.pk}}">{{category.title}}</option>
                        {% endif %}
                    {% endfor %}
                </select>
                </div>