My first time with Django and StackOverflow so could do with a little help.
A Platform has many Categories and a Category can belong to many Platforms. A product belongs to one Platform and one or more of that Platforms Categories.
So this is what I have so far for my Models:
class Category(models.Model):
name = models.CharField(max_length=50, unique=True)
is_active = models.BooleanField(default=True)
def __unicode__(self):
return self.name
class Platform(models.Model):
name = models.CharField(max_length=50, unique=True)
is_active = models.BooleanField(default=True)
categories = models.ManyToManyField(Category)
def __unicode__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=50)
is_active = models.BooleanField(default=True)
platform = models.ForeignKey('Platform')
def __unicode__(self):
return self.name
class Meta:
unique_together = ("platform", "category")
All looks ok when in shell but what I can't fully understand is how do I narrow down the Categories down based upon the Platform when I create a new Product? Ideally I would be able to get this working within the admin screens?
Does this Model look ok or can I do it better?