Top "Django-queryset" questions

Django querysets are the primary abstraction for retrieving objects from Django's ORM system

Django filter versus get for single object?

I was having a debate on this with some colleagues. Is there a preferred way to retrieve an object in …

django django-models django-queryset
sql "LIKE" equivalent in django query

What is the equivalent of this SQL statement in django? SELECT * FROM table_name WHERE string LIKE pattern; How do …

python sql django django-models django-queryset
Django filter queryset __in for *every* item in list

Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model): name = …

python django filter django-queryset
Raw SQL queries in Django views

How would I perform the following using raw SQL in views.py? from app.models import Picture def results(request): …

django django-models django-views django-queryset
Django SUM Query?

I have a query akin to the following: SELECT SUM(ISNULL(table.name)) FROM table How does that SUM translate …

python django django-queryset
Get last record in a queryset

How can I retrieve the last record in a certain queryset?

django django-queryset
How to do SELECT COUNT(*) GROUP BY and ORDER BY in Django?

I'm using a transaction model to keep track all the events going through the system class Transaction(models.Model): actor = …

django django-queryset
Get distinct values of Queryset by field

I've got this model: class Visit(models.Model): timestamp = models.DateTimeField(editable=False) ip_address = models.IPAddressField(editable=False) If …

django field distinct django-queryset
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
django - convert a list back to a queryset

I have a handful of records that I would like to sort based on a computed value. Got the answer …

python django list sorting django-queryset