tback
tback

Reputation: 11561

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 Profile:

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.

Upvotes: 4

Views: 537

Answers (1)

rrauenza
rrauenza

Reputation: 6983

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='+')

Upvotes: 3

Related Questions