Created
July 3, 2012 03:58
-
-
Save h3/3037571 to your computer and use it in GitHub Desktop.
Get first element of a QuerySet
This file contains 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
def getLastDateModification(self): | |
qs = self.themefile_set.order_by('-date_modified') | |
# NEVER !! | |
return qs[0].date_modified | |
# The most efficient/failsafe way (this will add LIMIT 1 to the query): | |
rs = list(qs[:1]) | |
return rs and rs[0].date_modified or None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment