I've read some, related, questions, but it's not very clear what the best practice is for my case. I'm a database n00b trying to learn, so patience is appreciated. My situation is as follows:
- 3 types of companies: Manufacturer, Reseller, ServiceNRepair (sharing about 10 attributes)
- 5 types of products: StuffedAnimals, Bicycles, Barbies (also sharing some attributes)
So to keep things DRY I tried multi table inheritance:
# company.models.py
class GenericCompany(models.Model):
name, description, address, etc
class Manufacturer(GenericCompany): #can manufacture different things
stuff_specific_to_manufacturers
product = models.ManyToMany(GenericProduct)
class Reseller(GenericCompany): #can sell different things
stuff_specific_to_manufacturers
product = models.ManyToMany(GenericProduct)
etc for ServiceNRepair
and similarly for the products,
# product.models.py
class GenericProduct(models.Model):
name, price, color, etc
class StuffedAnimal(GenericProduct):
fluffyness, ears_or_not, etc
class Bicycle(GenericProduct):
wheel_diameter, weight, etc
etc for Barbies
Now I'm going to need to perform queries like
- Show all products that are red (this is easy)
- What products does this manufacturer produce?
- Find all bicycles that reseller X sells
But can I do so with M2M? Manufacturer.objects.filter(product_icontains ='something')
such things won't work. So, I'm I totally on the wrong path? Is the typical solution to use ContentTypes? I would just like some direction about what to study next to tackle this problem which surely must be quite common. Any tips appreciated. Thank you.