Top "Django-models" questions

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

Django dynamic model fields

I'm working on a multi-tenanted application in which some users can define their own data fields (via the admin) to …

python django dynamic django-models django-custom-manager
Django modelform NOT required field

I have a form like this: class My_Form(ModelForm): class Meta: model = My_Class fields = ('first_name', 'last_name' , …

django django-forms optional django-models
How to serialize Django queryset.values() into json?

I have a model that has many fields, however for this problem I only need 3 of those fields. When I …

python json django django-models django-serializer
Manager isn't accessible via model instances

I'm trying to get model objects instance in another one and I raise this error : Manager isn't accessible via topic …

django django-models instance django-managers
Get django object id based on model attribute

I have a basic model named "Places" which has this view: def view_index(request, place_name): The user will …

django django-models django-views django-urls
Django: get the first object from a filter query or create

In Django, queryset provides a method called get_or_create that either returns an objects or creates an object. However, …

django django-models django-queryset
How to filter objects for count annotation in Django?

Consider simple Django models Event and Participant: class Event(models.Model): title = models.CharField(max_length=100) class Participant(models.Model): …

python django django-models django-aggregation
How to add a calculated field to a Django model

I have a simple Employee model that includes firstname, lastname and middlename fields. On the admin side and likely elsewhere, …

python django-models django-admin
Dropdown in Django Model

I want to create a field in Django models.py which will render as a dropdown and user can select …

django django-models django-forms
Django - Overriding the Model.create() method?

The Django docs only list examples for overriding save() and delete(). However, I'd like to define some extra processing for …

django django-models django-forms