开发者

django: Selecting a freign key from 2 models

I am developing a blog styled application. I w开发者_运维技巧ant to implement something like custom tags. (Trying to do the tag app myself, so I can learn something).

So I want to be able to create tags in admin interface, and want to be able to assign the to either my Section or Article model. I wonder if that's possible to make an model which will give ability to chose object (e.g. article or section)

I was looking on django comments app, but I would like to do something more simple. Is that possible?


Have a look at generic relations. A generic foreign key enables you to have have a foreign key relationship without having to define the target model in the code.

But I'd recommend to use django-tagging, which is a ready-made generic django tagging application which provides you a lot of additional functionality and is pretty easy to integrate (it also works via generic relations).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜