Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Category(models.Model):
- name = models.CharField(max_length=100)
- class Product(models.Model):
- name = models.CharField(max_length=100)
- description = models.TextField(null=True, blank=True)
- price = models.DecimalField(max_digits=10, decimal_places=2)
- category = models.ForeignKey("Category", on_delete=models.CASCADE) # ONE TO MANY ВРЪЗКА С Category
- is_available = models.BooleanField(default=True)
- def __str__(self):
- return f"{self.category.name}: {self.name}"
- class Customer(models.Model):
- username = models.CharField(max_length=50, unique=True)
- class Order(models.Model):
- customer = models.ForeignKey("Customer", on_delete=models.CASCADE) # ONE TO MANY ВРЪЗАКА С Customer
- products = models.ManyToManyField("Product", through="OrderProduct") # MANY TO MANY ВРЪЗКА С Product
- class OrderProduct(models.Model):
- order = models.ForeignKey("Order", on_delete=models.CASCADE) # ONE TO MANY ВРЪЗКА С Order
- product = models.ForeignKey("Product", on_delete=models.CASCADE) # ONE TO MANY ВРЪЗКА С Product
- quantity = models.PositiveIntegerField()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement