使用Django为电子商务产品建立关系?

时间:2018-09-09 11:22:12

标签: django python-3.7

from django.db import models
class books_category(models.Model):
    name                =models.CharField(max_length=200,unique=True)
    description         =models.TextField()
    #slug               =models.SlugField(max_length=200,unique=True,help_text='unique value for product page url')
    is_active           =models.BooleanField(default=True)
    #meta_keywards      =models.CharField("meta_keyward",max_length=255,help_text='Comma-delimited of SEO keywards for meta tag')
    #meta_description   =models.CharField("meta_description",max_length=255,help_text='content for meta tag')
    created_at          =models.DateTimeField(auto_now_add=True)
    updated_at          =models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.name


class books(models.Model):
    name                =models.CharField(max_length=200,unique=True)
    description         =models.TextField()
    #slug               =models.SlugField(max_length=200,unique=True)
    author              =models.CharField(max_length=200)
    publisher           =models.CharField(max_length=200)
    is_active           =models.BooleanField(default=True)
    is_bestseller       =models.BooleanField(default=False)
    is_featured         =models.BooleanField(default=False)
    is_deal_of_the_day  =models.BooleanField(default=False)
    is_new_arrival      =models.BooleanField(default=False)
    quantity            =models.IntegerField()
    image               =models.ImageField(upload_to='product/',blank=True)
    #meta_keywards       =models.CharField("meta_keyward",max_length=255,help_text='Comma-delimited of SEO keywards for meta tag')
    #meta_description    =models.CharField("meta_description",max_length=255,help_text='content for meta tag')
    created_at          =models.DateTimeField(auto_now_add=True)
    updated_at          =models.DateTimeField(auto_now=True)
    old_price           =models.DecimalField(decimal_places=2,max_digits=10,null=True)
    price               =models.DecimalField(decimal_places=2,max_digits=10,blank=True,default=0.00)
    #categories          =models.OneToManyField(category_name)

    def __str__(self):
        return self.name

class  cricket_bat(models.Model):
    name                =models.CharField(max_length=200,unique=True)
    description         =models.TextField()
    size                =models.CharField(max_length=100)
    willow_type         =models.CharField(max_length=100)
    width               =models.IntegerField()
    height              =models.IntegerField()
    brand_name          =models.CharField(max_length=100)
    cover_included      =models.BooleanField(default=True)
    toe_guard           =models.BooleanField(default=True)
    ideal_for           =models.CharField(max_length=100) #men,boys,women,girls
    suitable_for        =models.CharField(max_length=100) #ball type
    curve               =models.BooleanField(default=True)
    anti_scuff_sheet    =models.BooleanField(default=False)
    handle_type         =models.CharField(max_length=100)
    handle_grip_type    =models.CharField(max_length=100)
    handle_material     =models.CharField(max_length=100)
    age_group           =models.PositiveIntegerField()
    created_at          =models.DateTimeField(auto_now_add=True)
    updated_at          =models.DateTimeField(auto_now=True)
    old_price           =models.DecimalField(decimal_places=2,max_digits=10,null=True)
    price               =models.DecimalField(decimal_places=2,max_digits=10,blank=True,default=0.00)


    def __str__(self):
        return self.name

这就是我的代码的样子。基本上,我希望通过创建一个可以存储所有字段然后调用特定产品的特定字段的类来提高效率,但是我不确定在django中是否可行。

0 个答案:

没有答案