Skip to content

Instantly share code, notes, and snippets.

@bulv1ne
Last active August 29, 2015 14:05
Show Gist options
  • Save bulv1ne/d9f1431373c2aef0c02c to your computer and use it in GitHub Desktop.
Save bulv1ne/d9f1431373c2aef0c02c to your computer and use it in GitHub Desktop.
Last Modified ListView
from django.db import models
from django.utils.timezone import now # for migrations
class MyModel(models.Model):
field1 = models.CharField(max_length=255)
last_modified_by = models.DateTimeField(
auto_now=True, default=now, db_index=True)
from django.views.decorators.http import condition
from django.views.generic.list import ListView
class LastModifiedListView(ListView):
def get(self, *args, **kwargs):
def wrapper(*args, **kwargs):
result = self.model.objects.latest('last_modified_by')
return result.last_modified_by
cond = condition(last_modified_func=wrapper)
get_f = super(LastModifiedListView, self).get
return cond(get_f)(*args, **kwargs)
class MyModelListView(LastModifiedListView):
model = MyModel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment