开发者

Django: Don't want related manager for two foreign keys to the same model

I want to get rid of two related managers in a Model because I will never need them. How can I get rid of them?

This is my User P开发者_运维问答rofile:

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)

    ...    

    default_upload_container=models.ForeignKey(Container,related_name='idontcare')
    default_query_container=models.ForeignKey(Container,related_name='idontcareneither')

Because default_upload_container and default_query_container are only user specific defaults I guess I will never query them 'backwards'. I still want easy drop down fields in the admin though.

Thanks for your help.


This is a very similar question to Django: How do i create a foreign key without a related name?

https://docs.djangoproject.com/en/dev/ref/models/fields/ :

If you’d prefer Django not to create a backwards relation, set related_name to '+' or end it with '+'. For example, this will ensure that the User model won’t have a backwards relation to this model:

user = models.ForeignKey(User, related_name='+')

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜