Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Product data model
- '''
- category = models.ManyToManyField(Category, blank=True)
- title = models.TextField(blank=False, null=False)
- created_by = models.ForeignKey(
- get_user_model(), on_delete=models.CASCADE)
- description = models.TextField(blank=False, null=False)
- price = models.FloatField(default=0.0, blank=False, null=False)
- product_image = models.ImageField(upload_to='images/', null=True)
- units_in_stock = models.IntegerField(default=1)
- created_at = models.DateTimeField(
- auto_now_add=True, blank=True, null=True)
- last_updated = models.DateTimeField(auto_now=True)
- last_updated_by = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, default=None,
- related_name='updated_by', null=True, blank=True)
- class Cart(models.Model):
- '''
- Cart For User
- '''
- user_id = models.OneToOneField(get_user_model(), on_delete=models.CASCADE)
- product = models.ManyToManyField(Product, blank=True,through='CartDetail')
- # quantity = models.IntegerField(default=1, null=False, blank=False)
- class CartDetail(models.Model):
- '''
- Further Data of Cart
- '''
- product_id = models.ForeignKey(Product, on_delete=models.CASCADE)
- cart_id = models.ForeignKey(Cart, on_delete=models.CASCADE)
- quantity = models.IntegerField(default=1, null=False, blank=False)
- class Meta:
- '''
- To make Product Id and User Id Unique
- '''
- unique_together = ('cart_id', 'product_id',)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement