I am building a news app for my website. I want to use a sort of tag system. Each news article can have different and 开发者_JS百科multiple tags. All tags are saved in a tag model, and i want to connect the tags to the newsarticle. Now is this possible with: tags = models.ForeignKey( TagsModel ) for one tag, but how i can do this with multiple of them?
Thank you!
Use django tagging.
In your model you do: tags = TagField()
and presto, you have tags that behave like you expect. The app also comes with several niceties to perform common tasks. e.g. parse input into tags or output the tags in templates.
In general, though, you can have ManyToMany fields like so:
some_things = models.ManyToManyField(OtherModel)
here are the docs for that. You can have multiple ManyToManyFields in a single model, you just need to specify related names.
精彩评论