【发布时间】:2017-08-30 23:13:57
【问题描述】:
类或模型
class Category(models.Model):
category_name = models.CharField(max_length=50)
company_name = models.CharField(max_length=50)
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)
def __unicode__(self):
return self.category_name
class Product(models.Model):
product_name = models.CharField(max_length=50)
category = models.CharField(max_length=50)
desc = models.CharField(max_length=120)
company_name = models.CharField(max_length=50, default=None)
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)
class ProductDetails(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
batch = models.CharField(max_length=50)
quantity = models.IntegerField()
cost = models.FloatField(null=True, blank=True, default=None)
mfg = models.DateTimeField()
exp = models.DateTimeField()
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)
class product_barcode(models.Model):
batch = models.ForeignKey(ProductDetails, on_delete=models.CASCADE)
barcode = models.BigIntegerField()
flag = models.IntegerField()
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)
1> 第一个任务 查找产品名称、成本、标志?使用 product_barcode 表的条形码值
类 S_history
class S_History(models.Model):
barcode = models.CharField(max_length=500)
email = models.CharField(max_length=100)
timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
2> 如果 S_History.barcode=prodcut_barcode.barcode 则创建列表
S_History 表可能包含多个相同条码的条目
列表看起来像
[{"product_name":"fff","cost":"999"},{"product_name":"xxxwww","cost":"55"}]
【问题讨论】:
标签: mysql django python-2.7 django-models