Top "Django-models" questions

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

How to limit the maximum value of a numeric field in a Django model?

Django has various numeric fields available for use in models, e.g. DecimalField and PositiveIntegerField. Although the former can be …

python django django-models numbers
Setting the selected value on a Django forms.ChoiceField

Here is the field declaration in a form: max_number = forms.ChoiceField(widget = forms.Select(), choices = ([('1','1'), (…

django django-models django-forms
What's the difference between select_related and prefetch_related in Django ORM?

In Django doc, select_related() "follows" foreign-key relationships, selecting additional related-object data when it executes its query. prefetch_related() does …

python django django-models django-orm
What is the most efficient way to store a list in the Django models?

Currently I have a lot of python objects in my code similar to the following: class MyClass(): def __init__(self, …

python django django-models
How to 'bulk update' with Django?

I'd like to update a table with Django - something like this in raw SQL: update tbl_name set name = …

django django-models
Django database query: How to get object by id?

Django automatically creates an id field as primary key. Now I need to get the object by this id. object = …

django django-models django-orm
How do I clone a Django model instance object and save it to the database?

Foo.objects.get(pk="foo") <Foo: test> In the database, I want to add another object which is …

python django django-models
Select DISTINCT individual columns in django?

I'm curious if there's any way to do a query in Django that's not a "SELECT * FROM..." underneath. I'm trying …

django django-models distinct django-queryset django-orm
Django request get parameters

In a Django request I have the following: POST:<QueryDict: {u'section': [u'39'], u'MAINS': [u'137']}> How do …

python django django-models django-views
how to import csv data into django models

I have some CSV data and I want to import into django models using the example CSV data: 1;"02-01-101101";"…

python django csv django-models export