class Macro(models.Model): TYPE_BRICK = 0 TYPE_LINE = 1 TYPE_PARQUET = 2 TYPE_WALL = 3 TYPE_ROOM = 4 TYPE_CHOICES = ((TYPE_BRICK, '造型砖'), (TYPE_LINE, '腰线框、波打线'), (TYPE_PARQUET, '拼花'), (TYPE_WALL, '墙面装修'), (TYPE_ROOM, '样板间')) type = models.IntegerField(default=TYPE_BRICK, choices=TYPE_CHOICES) # 用户 account = models.ForeignKey('CustomerAccount', related_name='macros', default=None, null=True, blank=True, on_delete=models.SET_NULL) # 商铺或电商的客户 other_account = models.ForeignKey('OtherAccount', related_name='macros', default=None, null=True, blank=True, on_delete=models.SET_NULL) paving_id = models.IntegerField(default=0) paving_name = models.CharField(max_length=200, default=None, null=True, blank=True) cnf_type = models.CharField(max_length=200, default=None, null=True, blank=True) cnf_name = models.CharField(max_length=200, default=None, null=True, blank=True) style_id = models.IntegerField(default=0) brands = models.ManyToManyField('ProductBrand', related_name='macros', through='MacroBrand') suitable_material = models.CharField(max_length=200, default=None, null=True, blank=True) cnf_body = models.FileField(upload_to=get_resources_path(), default=None, blank=True, null=True) img = models.ImageField(upload_to=get_resources_path(), default=None, blank=True, null=True) edge = models.IntegerField(default=1) is_share = models.BooleanField(default=False) active = models.BooleanField(default=True) class Meta: db_table = 'scheme_macro'
class Distributor(models.Model): # 供应商 account = models.OneToOneField('CustomerAccount', related_name='distributor', default=None, null=True, blank=True, on_delete=models.SET_NULL) name = models.CharField(max_length=200, default=None, null=True, blank=True) # 域名 domain = models.CharField(max_length=200, default=None, null=True, blank=True) # 公司名称 company_name = models.CharField(max_length=200, default=None, null=True, blank=True) # 描述 description = models.CharField(max_length=2000, default=None, null=True, blank=True) # 注册号 register_no = models.CharField(max_length=50, default=None, null=True, blank=True) # 身份信息 cert_no = models.CharField(max_length=50, default=None, null=True, blank=True) # 银行帐号 bank_no = models.CharField(max_length=50, default=None, null=True, blank=True) # 营业执照 business_license = models.FileField(default=None, null=True, blank=True, upload_to=get_resources_path()) brands = models.ManyToManyField('ProductBrand', through='DistributorBrand', related_name='distributors') designers = models.ManyToManyField('Designer', related_name='designer_distributors', through='DesignerDistributor') class Meta: db_table = 'customers_distributor' def __unicode__(self): return '%s' % self.name
class Designer(models.Model): account = models.OneToOneField('CustomerAccount', related_name='designer', default=None, null=True, blank=True, on_delete=models.SET_NULL) # 身份信息 cert_no = models.CharField(max_length=50, default=None, null=True, blank=True) # 社交帐号 social_account = models.CharField(max_length=50, default=None, null=True, blank=True) # 所在地 location = models.CharField(max_length=200, default=None, null=True, blank=True) # 公司名称 company_name = models.CharField(max_length=200, default=None, null=True, blank=True) # 公司地址 company_address = models.CharField(max_length=200, default=None, null=True, blank=True) # 设计风格 design_style = models.CharField(max_length=200, default=None, null=True, blank=True) # 个人简介 personal_profile = models.CharField(max_length=500, default=None, null=True, blank=True) # 身份证附件正面 cert_attachment_front = models.ImageField(default=None, null=True, blank=True, upload_to=get_resources_path()) # 身份证附件背面 cert_attachment_back = models.ImageField(default=None, null=True, blank=True, upload_to=get_resources_path()) # 设计师资格证正面 designer_cert_front = models.ImageField(default=None, null=True, blank=True, upload_to=get_resources_path()) # 设计师资格证背面 designer_cert_back = models.ImageField(default=None, null=True, blank=True, upload_to=get_resources_path()) class Meta: db_table = 'customers_designer' def __unicode__(self): return '%s' % self.name
class CustomerAccount(models.Model): SOURCE_MAIN = 0 SOURCE_DESIGN = 1 SOURCE_OR = 2 SOURCE_SHOP = 3 SOURCE_CHOICES = ((0, '官网'), (1, '设计师平台'), (2, '电商平台'), (3, '商铺')) ROLE_NORMAL = 0 ROLE_DESIGNER = 1 ROLE_OR = 2 ROLE_SHOP = 3 ROLE_DECORATION = 4 ROLE_MANUFACTORY = 5 ROLE_CHOICES = ((0, '普通用户'), (1, '设计师'), (2, '供应商'), (3, '供应商'), (4, '装修公司'), (5, '供应商')) GENDER_MALE = 0 GENDER_FEMALE = 1 GENDER_CHOICES = ( (GENDER_MALE, '男'), (GENDER_FEMALE, '女'), ) no = models.IntegerField(default=0) # 来源 source = models.IntegerField(choices=SOURCE_CHOICES, default=SOURCE_MAIN) # 来源名称 source_name = models.CharField(max_length=200, default=None, null=True, blank=True) # 用户名 username = models.CharField(max_length=200, default=None, null=True, blank=True) password = models.CharField(max_length=50, default=None, null=True, blank=True) # 角色 role = models.IntegerField(choices=ROLE_CHOICES, default=ROLE_NORMAL) # 状态 active = models.BooleanField(default=True) # 注册日期 register_date = models.DateTimeField(auto_now_add=True) # 头像 avatar = models.ImageField(default=None, null=True, blank=True, upload_to=get_resources_path()) # 真实姓名 real_name = models.CharField(max_length=200, default=None, null=True, blank=True) # 性别 gender = models.IntegerField(choices=GENDER_CHOICES, default=GENDER_MALE) # 生日 birth_date = models.DateField(default=None, null=True, blank=True) # 手机号码 phone = models.CharField(max_length=50, default=None, null=True, blank=True) # 邮箱 email = models.EmailField(max_length=200, default=None, null=True, blank=True) email_certified = models.BooleanField(default=False) # 电话有效性认证 phone_certified = models.BooleanField(default=False) # 认证 certified = models.BooleanField(default=False) # 审核 approved = models.BooleanField(default=False) class Meta: db_table = 'customers_customeraccount' def __unicode__(self): return '%s: %s' % (self.source_unicode, self.username) @property def role_unicode(self): return CustomerAccount.ROLE_CHOICES[self.role][1] @property def gender_unicode(self): return CustomerAccount.GENDER_CHOICES[self.gender][1] @property def customer_no(self): source = '' if self.source == 0: source = 'o' elif self.source == 1: source = 'd' elif self.source == 2: source = 'e' elif self.source == 3: source = 's' no = self.no for i in range(4 - len('%s' % self.no)): no = '0%s' % no role = '' if self.role == 0: role = 'n' elif self.role == 1: role = 'a' elif self.role == 2: role = 'e' elif self.role == 3: role = 's' elif self.role == 4: role = 'd' elif self.role == 5: role = 'm' return '%s%s%s%s' % (source, role, self.register_date.strftime('%Y%m%d'), no) @property def register_date_format(self): return self.register_date and utc2local( self.register_date).strftime('%Y-%m-%d %H:%M:%S') or 'N/A' @property def source_unicode(self): if self.source_name: return self.source_name else: return CustomerAccount.SOURCE_CHOICES[self.source][1]
class Manufactor(models.Model): name = models.CharField(max_length=200, default=None, null=True, blank=True) no = models.IntegerField(default=0, null=False) # 厂商 manufacturer = models.OneToOneField('CustomerAccount', related_name='manufactory', default=None, null=True, blank=True, on_delete=models.SET_NULL) # 拿到代理的经销商 customers = models.ManyToManyField('CustomerAccount', related_name='manufactors', through='CustomerManufactor') # 注册号 register_no = models.CharField(max_length=50, default=None, null=True, blank=True) # 营业执照 business_license = models.FileField(default=None, null=True, blank=True, upload_to='business_license/') # 省 province = models.CharField(max_length=200, default=None, null=True, blank=True) # 市 city = models.CharField(max_length=200, default=None, null=True, blank=True) # 区 area = models.CharField(max_length=200, default=None, null=True, blank=True) # 联系人 contact = models.CharField(max_length=200, default=None, null=True, blank=True) # 联系电话 contact_no = models.CharField(max_length=200, default=None, null=True, blank=True) image = models.ImageField(default=None, null=True, blank=True, upload_to=get_resources_path()) active = models.BooleanField(default=True) class Meta: db_table = "products_manufactor" def __unicode__(self): return '%s(%s)' % (self.name, self.manufactor_no) @property def manufactor_no(self): return 'd%s' % self.no
class Apartment(models.Model): ORIENTATION_SOUTH = 0 ORIENTATION_NORTH = 1 ORIENTATION_EAST = 2 ORIENTATION_WEST = 3 ORIENTATION_EASTSOUTH = 4 ORIENTATION_EASTNORTH = 5 ORIENTATION_WESTNORTH = 6 ORIENTATION_WESTSOUTH = 7 ORIENTATION_CHOICES = ((ORIENTATION_SOUTH, '南'), (ORIENTATION_NORTH, '北'), (ORIENTATION_EAST, '东'), (ORIENTATION_WEST, '西'), (ORIENTATION_EASTSOUTH, '东南'), (ORIENTATION_EASTNORTH, '东北'), (ORIENTATION_WESTNORTH, '西北'), (ORIENTATION_WESTSOUTH, '西南')) property = models.ForeignKey('Property', related_name='apartments') # 编号 no = models.IntegerField(default=0) # 户型编号 apartment_no = models.CharField(max_length=200, default=None, null=True, blank=True) # 户型名称 name = models.CharField(max_length=200, default=None, null=True, blank=True) # 面积 acreage = models.DecimalField(max_digits=20, decimal_places=2) # 室 room_count = models.IntegerField(default=0) # 厅 hall_count = models.IntegerField(default=0) # 厨 kitchen_count = models.IntegerField(default=0) # 卫 restroom_count = models.IntegerField(default=0) # 层高 height = models.DecimalField(max_digits=4, decimal_places=2) # 朝向 orientation = models.IntegerField(choices=ORIENTATION_CHOICES, default=ORIENTATION_SOUTH) # 卧室描述 room_description = models.CharField(max_length=500, default=None, null=True) # 客厅描述 living_room_description = models.CharField(max_length=500, default=None, null=True) # 餐厅描述 dining_room_description = models.CharField(max_length=500, default=None, null=True) # 卫生间描述 restroom_description = models.CharField(max_length=500, default=None, null=True) # 花园描述 garden_description = models.CharField(max_length=500, default=None, null=True) # 其他描述 other_description = models.CharField(max_length=500, default=None, null=True) # 户型图 preview = models.ImageField(upload_to=get_resources_path(), default=None, null=True) create_time = models.DateTimeField(auto_now_add=True) update_time = models.DateTimeField(auto_now=True) active = models.BooleanField(default=True) def orientation_unicode(self): return Apartment.ORIENTATION_CHOICES[self.orientation][1] def time_format(self): if not self.create_time and not self.update_time: return '0000-00-00 00:00:00' elif self.create_time and not self.update_time: return utc2local(self.create_time).strftime('%Y-%m-%d %H:%M:%S') else: return utc2local(self.update_time).strftime('%Y-%m-%d %H:%M:%S') class Meta: db_table = 'property_apartment'