Friday, October 23, 2015

Re: Reverse query name clashe with a M2M and through

Hi Gagaro,

Intermediate models are just like other in this regard, they create a related relation hence the reported clash.

You should either add related_name='+' on your Wishlist related fields or give them a unique name.

Simon

Le vendredi 23 octobre 2015 06:01:30 UTC-4, Gagaro a écrit :
Hello,

I have a situation I don't really understand. I have the following models:

class Wishlist(models.Model):
    wine
= models.ForeignKey('Wine')
    user
= models.ForeignKey('User')


class Wine(models.Model):
    name
= models.CharField(max_length=32)


class User(models.Model):
    name
= models.CharField(max_length=32)
    wishlist
= models.ManyToManyField(Wine, through=Wishlist)

And the following error:

models_test.Wishlist.user: (fields.E303) Reverse query name for 'Wishlist.user' clashes with field name 'User.wishlist'.
HINT: Rename field 'User.wishlist', or add/change a related_name argument to the definition for field 'Wishlist.user'.

Is that an intended behaviors? In my understanding, there is no related relation created for through models (IE: we can't directly get the Wishlist instance from the User one). Why would the names clash in this case? And why does it clashes on wishlist, the reverse relation shouldn't be wishlist_set and not wishlist?

Thanks.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f7b01ec8-dcd3-4df9-83d2-8f9e61e92d64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment