Sent too soon!

def calculate_score(self):
     return
x.m2m_set.filter(condition).aggregate(avg=Avg('m2m_subfield__score'))['avg']

returns the "Relation fields do not support nested lookups" error

On Fri, Apr 8, 2016 at 11:27 AM, Jonty Needham <jontyneed...@gmail.com>
wrote:

> I'm not sure what this error means or how to resolve it. I'm guessing it's
> because in my model I'm trying to assign a field to the value of the
> average of all the many2many's from another field. But I can do this at the
> command line happily, yet when I put it on a submethod I can't do it, so I
> don't understand what's going wrong.
>
> This works:
>
> x.field_name =
> x.m2m_set.filter(condition).aggregate(avg=Avg('m2m_subfield__score'))['avg']
> x.save()
>
> Yes including the method on the model for x as follows:
>
> def calculate_score(self):
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANOQRbzCBpNrL6skXKvKHi0c6MP-dS4LU_AgQB5_8aZnha1c3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to