0

I have a two generic models in my app: ProductAttributes and ProductAttributesValue (besides Product and ProductCategory, which are not relevant for this discussion).

These two models contain respectively all the different attributes and their values. For example, "brand" as an Attribute, and "nike" and "addidas" as its Attribute Values.

I'm running into an issue with this setup, though, as I want to create a page for each brand. I think this would be easier, if brands did not share model with other attributes, like color, size etc., which I do not want to create unique pages for. There may also be other scenarios.

In general, what's the pros and cons of having a unique model for each Product Attribute, versus having a shared model?

Note: I want to still be able to have long URLs that contain one category and several attribute values, like domain.com/shoes/red/nike

  • You're describing EAV (Entity-Attribute-Value) - see e.g. https://stackoverflow.com/questions/2224234/database-eav-pros-cons-and-alternatives for a discussion. – AKX Jan 19 '22 at 19:42
  • And anyway, your URL scheme doesn't need to correspond to your database design at all. Also: would `/shoes/red/nike/` and `/shoes/nike/red/` be interchangeable..? – AKX Jan 19 '22 at 19:45
  • I'm mentioning two solutions, so which one is EAV? And about the URLs: No, because I have implemented logic (based on the ID's of the product attributes), so that the lower value'd attribute value always comes first in the URL. Else the view returns 404. This is another caveat to my current solution with a shared Attribute and AttributeValue models: The view and the template have A LOT of logic. For example to determine which attributes to show in the sidebar filter of the category page, based on the products on that particular page – Frederik Faarup Jan 19 '22 at 20:19

0 Answers0