6👍
Ross’s answer is great enough.
But if you really need a latest()
, implementing a custom QuerySet can do this.
“Decorator” way:
class Users(Document):
username = StringField()
@queryset_manager
def latest(doc_cls, queryset):
return queryset.order_by('-id').first()
“meta” way:
class UsersQuerySet(QuerySet):
def latest(self):
return self.order_by('-id').first()
class Users(Document):
meta = {'queryset_class': UsersQuerySet}
Now you can:
Users.objects.latest()
# or
Users.latest()
- Django string concatenation inside template tag best practice
- Django serialize to JSON
- CheckBox Input Validation in Django
- Django 1.6 and django-registration: built-in authentication views not picked up
- Checking if a Django user has a password set
Source:stackexchange.com