Could someone explain to me where I can find information about why this works in Django? I did some research in the official documentation and couldn’t find anything.
from django.db import models
class Document(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100)
# Query using an integer
document1 = Document.objects.get(id=1)
# Query using a string that can be converted to an integer
document2 = Document.objects.get(id='1')
# Both queries should yield the same result
I check this pages in the official documentation:
- https://docs.djangoproject.com/en/5.0/ref/models/fields/#model-field-types
- https://docs.djangoproject.com/en/5.0/topics/db/queries/
- https://docs.djangoproject.com/en/5.0/ref/models/lookups/