假设我有一个房产,它可以出售和/或出租(每个都有相关的价格),我应该如何构建我的模型?
A:
class Property(models.Model):
name = models.CharField()
sale_price = models.DecimalField(max_digits=14, decimal_places=2)
rent_price = models.DecimalField(max_digits=14, decimal_places=2)
乙:
class Property(models.Model):
name = models.CharField()
CATEGORY_CHOICES = (
(u'sale', u'Sale'),
(u'rent', u'Rent'),
)
class Category(models.Model):
property = models.ForeignKey('Property')
name = models.CharField(max_length=25, choices=CATEGORY_CHOICES)
price = models.DecimalField(max_digits=14, decimal_places=2)
C:
class Property(models.Model):
name = models.CharField()
class Sale(models.Model):
property = models.ForeignKey('Property')
price = models.DecimalField(max_digits=14, decimal_places=2)
class Rent(models.Model):
property = models.ForeignKey('Property')
price = models.DecimalField(max_digits=14, decimal_places=2)
如果我想添加销售/租赁特定字段,我认为 C 会给我更大的灵活性。结构 B 似乎更适合查询,但我不确定。
假设我选择了 C,例如,如何查询正在出售的房产?