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.


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)


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


 <label for="select" class="">Category Parent</label>
                    <select name="parent" id="exampleSelect"
                     <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.title}}</option>
                        {% endif %}
                    {% endfor %}