BrandProduct relation not unique?

Create issue
Issue #930 new
drjeep created an issue

I'm not sure if this is intentional or a bug, but shouldn't the //BrandProduct// relation be unique? Currently it's possible to add duplicate records to this table, e.g.

{{{ BrandProduct.objects.create(brand=b, product=p) }}}

This is easy enough to fix by adding //unique_together// to the model as follows, but I'm not sure if this will have unintended consequences down the line.

{{{ class BrandProduct(models.Model): ... Meta: ... unique_together = (brand, product) }}}

Also, I'm curious as to why this relation uses //through=BrandProduct// as there aren't any additional fields in this model. For consistency with e.g. product categories wouldn't it be easier if we could do this instead?

{{{ brand.products.add(p) }}}

Hopefully all this makes sense. I'm looking forward to further contributing to Satchmo.

Comments (0)

  1. Log in to comment