Last active
December 14, 2015 02:39
-
-
Save nkryptic/5015694 to your computer and use it in GitHub Desktop.
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
import operator | |
from django.db import models | |
from django.contrib.auth.models import User | |
from myapp.models import License | |
or_list = [] | |
values = User.objects.values_list('id').annotate(models.Max('licenses__created_at')) | |
for pk, dt in values: | |
or_list.append(models.Q(user__pk=pk, created_at=dt)) | |
qs = License.objects.filter(reduce(operator.or_, or_list)) | |
for license in qs: | |
print license.id, license.created_at, license.user.username |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment