Hi Simon, thanks for the answer, it cleared some things up.
However, I still have a question. The reverse relation is *wishlist_set* by
default. Why is Django bothered if the attribute is name *wishlist* (I
would understand if I named my attribute *wishlist_set*)?
On Friday, 23 October 2015 15:40:42 UTC+2, Simon Charette wrote:
>
> 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 [email protected].
To post to this group, send email to [email protected].
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/3c41497b-94d7-4c65-8bef-7a29b00e540f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.