2👍
✅
Also you can try to use annotate
from django.db.models import Max
Plan.objects.values('plan_crisisID__crisis_ID').annotate(max_pk=Max('plan_ID'))
0👍
After some trying, I did something like this:
for crisis in crisisList:
plansInCrisis = planList.filter(plan_crisisID__crisis_ID=crisis.crisis_ID)
max = plansInCrisis[0]
for plan in plansInCrisis:
if(plan.plan_ID > max.plan_ID ): max = plan
toDisplay.append(max)
As i’m new to python programming, I assume this is bad practice if I loop twice without using any inbuilt methods, but it works for now. Sorry for the poor question, cheers
- [Django]-How to combine values filter with a Queryset of a certain Foreignkey field on my Django Model
- [Django]-How can I resolve this linting error? "Consider adding meta keywords. <html lang="en-US"> (H031)"
- [Django]-Django model field that's actually a reference to a field in a related model
- [Django]-Django 'ImportError: cannot import name url'
- [Django]-How to pass variables to login page in django 1?
Source:stackexchange.com