As written here in Django docs, I needed to add +
in the end of related_name attribute in m2m model and set related_name in m2m field different from its name.
Django m2m symmetrical False raises error
-
31-07-2022 - |
Question
I can't runserver for the model with m2m (ManyToManyField). The models' field itself looks like this:
...
class Some(TimeStampedModel):
relate = models.CharField(max_length=10000, blank=False)
related_relate = models.ManyToManyField('self', through='RelatedM2M',
symmetrical=False, related_name=_('related_relate'))
...
then facing the import error:
django.core.urlresolvers.NoReverseMatch: Reverse for 'related_phrases' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
and I can't understand how it works... From this post I've found that I need to create the reverse relationship manually yourself via the through model
but what does this mean? What exactly happens that it throws this error and how to handle m2m asymmetrical fields in models that are related to themselves?
Update
django.core.urlresolvers.NoReverseMatch:
class NoReverseMatch(Exception):
pass
??
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow