0

Is it a good idea to use contenttypes in my project ?, I have a user model, post and event, all three have in common an image field.

I just start with django and I prefer that this does not cause me problems later.

cupstgo
  • 79
  • 1
  • 8
  • This is primarily opinion based but if it's only one image per instance just add an image field to each of the models. If there will be multiple images per instance then consider using a generic relation (ie. contenttypes). – Selcuk Jul 11 '17 at 04:47
  • I'd avoid using content types. You could make a `MyAppImage` class and give the other models a `ForeignKey` to an object if they all share it. – The_Cthulhu_Kid Jul 11 '17 at 05:39
  • Creating an alternative class for images makes it difficult to index in Haystacks etc.. for example you query "abc", all the objects will be return with the keyword, but how would you get the Images associated with each object? It wouldn't be very straight forward. – almost a beginner Jul 11 '17 at 06:04
  • @Selcuk Thank you – cupstgo Jul 11 '17 at 14:28
  • @almostabeginner I had not thought of that, thank you – cupstgo Jul 11 '17 at 14:29
  • @The_Cthulhu_Kid thank you – cupstgo Jul 11 '17 at 14:29
  • 1
    @almostabeginner it is extremely straight forward... – The_Cthulhu_Kid Jul 12 '17 at 05:00
  • @The_Cthulhu_Kid I'm having some trouble, please do help; https://stackoverflow.com/questions/45004561/index-related-table-using-haystack-whoosh – almost a beginner Jul 12 '17 at 05:04

0 Answers0