0👍
✅
In the end I went for a dict that stores a list of the calculated fields, as so:
data = {}
for m1 in Model1.objects.all():
list = []
model2s = m1.model2_set.filter(user=request.user)
if model2s:
list.append(calculated field)
list.append(Another calculated field)
data[m1.name] = list
1👍
Something like the following should work to get the dict you are referring to:
data = {}
for m1 in Model1.objects.all():
data[m1.name] = Model2.objects.filter(model1=m1)
- [Answer]-Adding inline formsets without javascript
- [Answer]-Django aggregate, annotate with range
- [Answer]-Django models: getting users from object
Source:stackexchange.com