reverse ordering date queries in django python

In my quest to understand queries to Django models I’ve been trying to get the last 3 added valid Avatar models with a query like:

newUserAv = Avatar.objects.filter(valid=True).order_by("date")[:3]

However this gives me the first three avatars added ordered by date. I’m sure this is so simple but I’ve had trouble finding it in the Django docs, how do I selected the LAST three avatar objects instead of the first?

Django admin ordering in reverse

In class ObjectAdmin(admin.ModelAdmin): ordering = [‘order’] Is there a way to order in reverse?

Reverse date time ordering [R]

I am Trying to order a DF by date.time (POSIXct object) with the most recent date.time first i.e. in reverse df1<-structure(list(date.time = structure(c(1368066412, 1365895151, 1365969188, 13661054

DRY in django queries, reverse queries, and predicates

I am frustrated that in Django I often end up having to write methods on a custom Manager: class EntryManager(Manager): def filter_beatle(self, beatle): return self.filter(headline__contains=beatle)

Django QuerySet ordering by number of reverse ForeignKey matches

I have the following Django models: class Foo(models.Model): title = models.CharField(_(u’Title’), max_length=600) class Bar(models.Model): foo = models.ForeignKey(Foo) eg_id = models.PositiveIntegerF

Ordering of Django models

I set up an ordering=’ordering_number’ Meta attribute to my Django model, thinking that Django will use it when comparing instances. (ordering_number is an IntegerField in my model.) For example, if I

Changing dictionary ordering in Python (Django)

I have Python code accessing data in a database (in Django): for result in request.user.results.all(): for word in result.word.all(): data.append(dict(zip([str(word.type.type)], [str(word.word)]))) w

django-cms apphook urls don’t work with reverse() using Python shell

I’ve created a django CMS apphook. Unfortunately I’m not able to reverse apphook urls using the Python shell. The file looks like: class ArticleApp (CMSApp): name = _(‘Article App’) app_nam

Django Reverse Inverse

Is there an inverse method for Django’s django.core.urlresolvers.reverse()? I want a function f(x) such that f(django.core.urlresolvers.reverse(‘shadowfax’)) == ‘shadowfax’. Does anybody have anything

Custom ordering in Django

How do you define a specific ordering in Django QuerySets? Specifically, if I have a QuerySet like so: [‘a10’, ‘a1’, ‘a2’]. Regular order (using Whatever.objects.order_by(‘someField’)) will give me [‘

Django MPTT ordering

I’m using MPTT tree structure in my Django project to organise comments. I have only 2 level : comment and comment of comment Everything works perfectly except the ordering. I would like to sort all C


Put a hyphen before the field name.


Reverse order with .reverse()

newUserAv = Avatar.objects.filter(valid=True).order_by("date").reverse()[:3]