Last active
April 27, 2020 18:05
-
-
Save susmithagudapati/6e49286e624eb9157730465f03f22c8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User(models.Model): | |
name = models.CharField(max_length=64, null=True) | |
class Category(models.Model): | |
name = models.CharField(max_length=128) | |
is_active = models.BoolenField(default=False) | |
created_by = models.ForeignKey( | |
User, on_delete=models.PROTECT, related_name='category_created_by', null=True) | |
class ProductAttribute(models.Model): | |
name = models.CharField(max_length=64) | |
class Product(models.Model): | |
name = models.CharField(max_length=128, db_index=True) | |
upc = models.CharField(max_length=32, unique=True) | |
stock = models.PositiveIntegerField(default=0) | |
category = models.ForeignKey( | |
Category, on_delete=models.PROTECT, related_name='categories', null=True) | |
attributes = models.ManyToManyField(ProductAttribute) | |
created_by = models.ForeignKey( | |
User, on_delete=models.PROTECT, related_name='product_created_by', null=True) | |
def __str__(self): | |
return "%s (%s)" % (self.name, ", ".join(attribute.name for attribute in self.attributes.all()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment