开发者

What are reverse generic relationships used for?

The documentation on contenttypes says this:

If you know which mode开发者_C百科ls you'll be using most often, you can also add a "reverse" generic relationship to enable an additional API.

But what's their practical use? I fail to understand.


If you have a model with:

A) Kitchen ---generic relation---> any food

But you know you will do often:

B) Vegetables.get_kitchen()

Instead of doing get_kitchen() manually, you can add the reverse relationship in the Vegetable model and it will get the Kitchen for you.

This kind of reverse relation is automaticly added to the other model for OneToMany relation using ForeignKey because you know which models are going to be on the both sides of the relation.

Since with generic relation, it can be any model, Django doesn't add the reverse relation for you. You have to specify it manually if you feel that you need it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜