This is more of a conceptual/engineering question than an actual programming question, but I keep going back and forth between what is the "right" thing to do here. For quick background, I am still a bit of a noob at python/django and don't have a ton of experience working with classes.
The program I'm trying to develop is an inventory management app.
There are multiple products but lets simplify and say one is shoes and one is clothing. Both products share some attributes (UPC, size, color, etc), but also have some unique attributes (shoe_width, clothing_type) as well.
Additionally, it seems like I should have a separate Product class (unique product attributes UPC, size shoe_width, clothing_type) and InventoryItem class (attributes unique to each piece of inventory such as price paid or condition) that inherits its corresponding Product class attributes.
EDIT2: clothing_type is unique to clothing, but shoe_width should be unique to the actual shoe InventoryItem and not the shoe Product. This sort of complicates the question, as now I'm thinking I'll need not only seperate Clothing and Shoe classes, but also ClothingInventoryItem & ShoeInventoryItem classes to deal with unique fields down at the inventory level.
Conceptually, I am trying to build this multi-purpose. Users should be able to view product information (not inventory related) and add products and inventory items via django admin or via spreeadsheet upload (spreadsheet hooks already built.)
So to the actual question, what is the correct way to implement the individual classes and what are some of the problems I may run into or drawbacks to doing so? I'm having a problem visualizing how this would work.
Should I:
A)
- Have a ProductType field (make two initial entries of "Shoe" & "Clothing")
- Have separate "Shoe" and "Clothing" classes which inherit ProductType via models.ForeignKey(ProductType). They would then have their own unique fields regardless if they share some fields.
- Have an InventoryItem class that then inherits Shoe or Clothing via ForeignKey.
The only limitation I can see is that the admin users would not be able to add new ProductType without me having to write a new class for that new ProductType (which is totally fine.)
Thanks in advance.
Edit: When I was initially typing this, the alternative scenario would be to do these relationships correctly via python nested classes and then feed the info into the django model classes...but this seems redundant and unnecessary.