Last active
August 29, 2015 14:05
-
-
Save bulv1ne/d9f1431373c2aef0c02c to your computer and use it in GitHub Desktop.
Last Modified ListView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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