python - Collect separate models in Django -


I have a model content .

But items have to handle images, videos, articles etc.

I think the best solution would be to model for each type of content:

  class image (models.model): image = ImageField () class Paragraph (models.Model): Title = CharField (max_length = 100) text = TextField () class video (models.Model): url = URLField ()  

  class content (models.Model): content = foreign key (=?)  

Actually a content object can contain more than 1 image, video, article etc. I So I think I'll need it to create another model, ContentSet which can contain 1 or more images, videos or articles.

The advantages will be that I can classify, comment and etc. in . In all models, instead of handling it, the content object image , aarti welfare , video

I want some advice on doing this, is it a good strategy? Would it be better to use Generic Relation ? What should my ForeignKey indicate in my content model?

I hope that it will be clear to understand my thoughts that I do not know any site, so I can not see anything to explain it better.

<

You can also model this relationship

I will use the Dinggo-Polymodel Because it is very light.

You can make a content superclass

  class content (polymorphic model): pass Class image (content): pass class passed (content): pass  

and then to get all sub-categories of content

Content.objects .all () Select_subclasses ()

I use your exact problem as the case used in the documentation link listed above, it is better examples and all the warnings included. I use it for production in large websites and it is an extremely easy API and joins as a consultant.

In addition, this is a good way because you can refer to the content in the FK and M2M relations


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -