Indeed, that makes sense!

As you said, the issue is that the error message is exactly the same than 
for a "normal" conflict.

Thank you for looking it up.

On Friday, 23 October 2015 16:40:46 UTC+2, Simon Charette wrote:
>
> Hi Gagaro,
>
> Upon further investigation it looks like the following thing is happening, 
> you find have a similar example in the documentation 
> <https://docs.djangoproject.com/en/1.8/topics/db/models/#extra-fields-on-many-to-many-relationships>
> .
>
> When you define an explicit through model Django generates a query name to 
> allow direct reference to the intermediate relationship.
>
> This query name is not customizable and is generated by lower casing the 
> intermediate model name ('wishlist' in your case and 'membership' in the 
> linked one).
>
> The clash you're getting here is between this implicit query name and your 
> User.wishlist field and would manifest itself if your were to call 
> User.objects.filter(wishlist__...) where Django couldn't differentiate the 
> field from the *through query name*.
>
> I guess the clash message could be more clear when a clash happens with 
> this implicit query name.
>
> Simon
>
> Le vendredi 23 octobre 2015 10:27:26 UTC-4, Gagaro a écrit :
>>
>> 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/fca6eeca-71b3-4a46-bec8-20a2be1910da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to