Top "Django-models" questions

For questions concerning use of the model class from the web framework Django.

Extending the User model with custom fields in Django

What's the best way to extend the User model (bundled with Django's authentication app) with custom fields? I would also …

django django-models django-authentication django-users
How to express a One-To-Many relationship in Django

I'm defining my Django models right now and I realized that there wasn't a OneToManyField in the model field types. …

django django-models
Fastest way to get the first object from a queryset in django?

Often I find myself wanting to get the first object from a queryset in Django, or return None if there …

python django performance django-models
Django Model() vs Model.objects.create()

What it the difference between running two commands: foo = FooModel() and bar = BarModel.objects.create() Does the second one immediately …

python django database django-models
Convert Django Model object to dict with all of the fields intact

How does one convert a Django Model object to a dict with all of its fields? All ideally includes foreign …

python django dictionary django-models
How to get the currently logged in user's user id in Django?

How to get the currently logged-in user's id? in models.py: class Game(models.model): name = models.CharField(max_length=255) …

django django-models django-authentication
select and update database record with a single queryset

How do I run an update and select statements on the same queryset rather than having to do two queries: …

sql django django-models orm django-queryset
What is a "slug" in Django?

When I read Django code I often see in models what is called a "slug". I am not quite sure …

python django django-models slug
Django: Display Choice Value

models.py: class Person(models.Model): name = models.CharField(max_length=200) CATEGORY_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) gender = models.CharField(…

python django django-models django-templates
When saving, how can you check if a field has changed?

In my model I have : class Alias(MyBaseModel): remote_image = models.URLField(max_length=500, null=True, help_text="A URL …

django image caching django-models