From Django documentation:
To compare two model instances, just use the standard Python comparison operator, the double equals sign: ==
. Behind the scenes, that compares the primary key values of two models.
More Related Contents:
- How to set a Django model field’s default value to a function call / callable (e.g., a date relative to the time of model object creation)
- What does on_delete do on Django models?
- Django: Get model from string?
- Dynamic File Path in Django
- Django: Populate user ID when saving a model
- Get model’s fields in Django
- Can django’s auth_user.username be varchar(75)? How could that be done?
- How to ‘bulk update’ with Django?
- Using a UUID as a primary key in Django models (generic relations impact)
- Custom QuerySet and Manager without breaking DRY?
- Django: Query using contains each value in a list
- How do you serialize a model instance in Django?
- Django delete FileField
- How to make email field unique in model User from contrib.auth in Django
- Why does django’s prefetch_related() only work with all() and not filter()?
- Select DISTINCT individual columns in django?
- Django ModelForm override widget
- ImageField overwrite image file with same name
- Django – filtering on foreign key properties
- How to register users in Django REST framework?
- Django : Unable to import model from another App
- django.db.utils.IntegrityError: UNIQUE constraint failed: rango_category__new.slug
- Can Django automatically create a related one-to-one model?
- Django Order By Date, but have “None” at end?
- How to add a sortable count column to the Django admin of a model with a many-to-one relation?
- Password field in Django model
- Creating Partial Indexes with Django 1.7
- Django: dynamic database file
- conversion of datetime Field to string in django queryset.values_list()
- Django Rest framework, how to include ‘__all__’ fields and a related field in ModelSerializer ?