On Tue, May 17, 2016 at 05:44:24AM -0700, François GUÉRIN wrote:
> Hi all, 
> 
> I'm a django application dev for a few years, so I'm pretty familiar with 
> it. I have a problem with a new django 1.9.6 application. I'm writing a 
> directory app, with a main model named "Association", which have 4 m2m 
> related fields :
> 
> 
> class Association(models.Model):
>     # ... other fields ...
> 
>     #: Activity domains.
>     #: note:: An association **MUST** have at least 1 activity, it can have 
> some more.
>     domains = models.ManyToManyField(Domain, verbose_name=_('domains'), 
> related_name='domain__associations')
> 
>     #: Targeted age groups
>     target_groups = models.ManyToManyField(TargetGroup, 
> verbose_name=_('target groups'),
>                                        blank=True, 
> related_name='target_group__associations')
> 
>     #: Locations where the activities of the association can take places
>     locations = models.ManyToManyField(Location, verbose_name=_('locations'),
>                                    blank=True, 
> related_name='location__associations')
> 
>     #: Affiliations 
>     affiliations = models.ManyToManyField(Affiliation, 
> verbose_name=_('affiliations'), blank=True,
>                                       
> related_name='affiliation__associations')
> 
> 
> When I try to access to related data; I always have (aka, for each related 
> field) a Field Error exception, has given in title. The keyword allways 
> asks for the field name in the relation table, and the field list displayed 
> are from the target table of the relation. Trlated tables are pretty simple 
> (name, description), but domain is a mptt table.
> 
> With factory_boy, I can create new `Association` items and insert new 
> relations to my related items, but I can't display them.
> 
> I'm stuck with this problem for a few days, that why I ask... I really 
> don't see what I didn't do... or understand !
> 
> Thanks for your help !

Hi François,

At a quick glance, it seems the error is that you put double
underscores into related_names. That cannot work, because
related_names should follow the same restrictions as regular field
names, and field names cannot contain double underscores, since Django
uses those to separate fields when traversing relations.

Cheers,

Michal

-- 
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/20160517124959.GI24966%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Digital signature

Reply via email to