Spaces:
Sleeping
Sleeping
File size: 1,910 Bytes
4b2adab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
from django.db import models
class Product(models.Model):
CONDITION_CHOICES = [
('new', 'New'),
('returned', 'Returned'),
('like_new', 'Like New'),
]
STATUS_CHOICES = [
('available', 'Available'),
('in_box', 'In Box'),
('sold', 'Sold'),
]
CATEGORY = [
('Electronics', 'Electronics'),
('Home & Kitchen', 'In Home & Kitchen'),
('Beauty & Personal Care', 'Beauty & Personal Care'),
('Sports & Fitness', 'Sports & Fitness'),
('Books & stationery', 'Books & stationery'),
]
name = models.CharField(max_length=200)
brand = models.CharField(max_length=100, blank=True, null=True)
category = models.CharField(max_length=100 , choices=CATEGORY , default='Electronics')
original_price = models.DecimalField(max_digits=10, decimal_places=2)
condition = models.CharField(max_length=20, choices=CONDITION_CHOICES, default='like_new')
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='available')
seller_name = models.CharField(max_length=150, blank=True, null=True)
def __str__(self):
return f"{self.name} ({self.brand})"
class MysteryBox(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
image = models.ImageField(null=True , blank= True)
price = models.DecimalField(max_digits=10, decimal_places=2)
category = models.CharField(max_length=100, default='mixed')
products = models.ManyToManyField(Product, blank=True)
stock_quantity = models.PositiveIntegerField(default=0)
is_featured = models.BooleanField(default=False)
def __str__(self):
return self.title
@property
def imageURL(self):
try:
url=self.image.url
except:
url=''
return url
|