0

I'm aware of this question was asked before, but that question doesn't have concise answer for my problem. I'm bit confused after seeing two examples in order to impelement OneToManyRelation.

In my example:

class Product(BaseModel):
    name = models.CharField(max_length=255)

class Advantages(BaseModel):
    title = models.CharField(max_length=255)
    product = models.ForeignKey(Product, CASCADE)

Different products can have many advantages linked to it, so I'm using ForeignKey for this, but here I saw that it is also possible to use cross table relation in order to implement OneToManyRelation

categories & sub categories with many to many relationship

class ProductAdvantage(BaseModel):
    title = models.CharField(max_length=255)
    product = models.ForeignKey(Product, CASCADE)

Which one best practice for the OneToManyRelation? One product can have many advantages Thank you for the answer

kenzo
  • 29
  • 1
  • 5
  • Read this [what does on_delete=models.PROTECT and on_delete=models.CASCADE do on Django models?](https://stackoverflow.com/questions/50502537/what-does-on-delete-models-protect-and-on-delete-models-cascade-do-on-django-mod) – Ashraful Islam May 25 '21 at 14:16
  • what does this have to do with my question? – kenzo May 25 '21 at 14:17
  • There is no difference between your examples other than the class name and the `PROTECT`/`CASCADE` value for the `on_delete` argument. Please refine your question as it is not clear what are you asking about. – GwynBleidD May 25 '21 at 14:42
  • @GwynBleidD. Let me clarify. I want to strucuture database for product and category. Product can link to many categories. So how I strucure such database table? – kenzo May 25 '21 at 14:48
  • Please edit the question and fix your examples, as they are misleading. For your question itself, it's still unclear to me what other database design do you mean as an alternative to the first example in your question. – GwynBleidD May 25 '21 at 14:49

0 Answers0