我用django构建了一个房地产管理系统。我想知道我的设计数据库是否错误,请让我知道对其进行改进
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
name = models.CharField(max_length=50)
image = models.ImageField(upload_to='profiles', default='logo.png')
phone = models.CharField(max_length=11, default='')
bio = models.CharField(max_length=100, default='')
city = models.CharField(max_length=20, default='erbil')
location = models.CharField(max_length=40, default='')
date = models.DateTimeField(default=datetime.now)
active = models.BooleanField(default=False)
def __str__(self):
return f'{self.user}'
class Listing(models.Model):
objects = ListingManager()
company = models.ForeignKey(User, on_delete=models.CASCADE )
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True, default='', blank=True)
address = models.CharField(max_length=200)
city = models.CharField(max_length=100, choices=city_choices, default='lodon')
estate_type = models.CharField(max_length=20, choices=estate_choices, default=house)
description = models.TextField(blank=True)
rent_sale = models.CharField(max_length=20, choices=rent_sale_choice, default=sale)
price = models.IntegerField()
bedrooms = models.IntegerField(default=0)
bathrooms = models.DecimalField(max_digits=2, decimal_places=1)
garage = models.IntegerField(default=0)
sqft = models.IntegerField()
sold = models.BooleanField(default=False)
sold_time = models.DateTimeField(default=datetime.now,blank=True)
photo_main = models.ImageField(upload_to='listings_main')
photo_1 = models.ImageField(upload_to='listings_1', blank=True)
photo_2 = models.ImageField(upload_to='listings_1', blank=True)
photo_3 = models.ImageField(upload_to='listings_1', blank=True)
photo_4 = models.ImageField(upload_to='listings_1', blank=True)
photo_5 = models.ImageField(upload_to='listings_1', blank=True)
photo_6 = models.ImageField(upload_to='listings_1', blank=True)
is_published = models.BooleanField(default=True)
list_date = models.DateTimeField(default=datetime.now, blank=True)
unless = models.CharField(default='', max_length=20)
我应该更改代码吗?如果是,应该在哪里更改?或为两个以上的表(类)建立模型
答案 0 :(得分:0)
对于模型中的时间戳记,请使用django utils TimeStampedModel
这些是我的建议:
对于https://github.com/stefanfoulis/django-phonenumber-field用于电话归档的电话,它将为您节省很多验证时间和时间
choices变量应按照Django文档的建议使用大写字母
对价格,卧室和任何有意义的模型使用PositiveIntegerField()
为什么洗手间= models.DecimalField()?
使用带有清单的外键将不同型号的照片分开