'What would be best if i want to relate one table to few others? (Django models example)
Existed models:
class OrderDocument(models.Model):
name = models.CharField(max_length=100)
file = models.FileField(upload_to=get_document_name)
order_group = models.ForeignKey(OrderGroup, on_delete=models.CASCADE, null=True, related_name='documents')
class Order(models.Model):
name = models.CharField(max_length=100)
order_group = models.ForeignKey(OrderGroup, on_delete=models.CASCADE, null=True, related_name='orders')
class OrderGroup(models.Model):
name = models.CharField(max_length=100)
I want to rewrite it for add ability to add OrderDocuments and choose with what table (Order or OrderGroup) it will related. Which way will the best in this case to implement it?
It can be more than 2 relations in future.
I don't want using m2m in Order and OrderGroup
Order can be without OrderGroup
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
