-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
39 lines (34 loc) · 1.46 KB
/
Copy pathmodels.py
File metadata and controls
39 lines (34 loc) · 1.46 KB
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
from django.db import models
from vendor.models import Vendor
# Create your models here.
class Product(models.Model):
MEDICINE = 'medicine'
DEVICES = 'devices'
HYGIENE = 'hygienic_product'
PRODUCT_TYPES = [
(MEDICINE, 'Medicine'),
(DEVICES, 'Devices'),
(HYGIENE, 'Hygienic Product'),
]
vendor = models.ForeignKey(Vendor,on_delete=models.CASCADE)
title = models.CharField(max_length=256)
meta_title = models.CharField(max_length=120,null=True)
medical_name = models.CharField(max_length=256, null= True)
slug = models.SlugField()
price = models.FloatField()
quantity = models.IntegerField()
manufacture_date = models.DateField(null=True)
expiry_date = models.DateField(null=True)
product_type = models.CharField(max_length=20, choices=PRODUCT_TYPES, default=MEDICINE)
description = models.TextField()
manufacturer = models.CharField(max_length=256)
timestamp = models.DateTimeField(auto_now_add=True)
def get_upload_path(instance, filename):
return 'product/{0}/{1}'.format(instance.product.id, filename)
class ProductImage(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
vendor = models.ForeignKey(Vendor,on_delete=models.CASCADE)
main = models.BooleanField(default=False)
image = models.ImageField(upload_to= get_upload_path ,blank=True)
description = models.CharField(max_length=256)
timestamp = models.DateTimeField(auto_now_add=True)