【发布时间】:2017-07-29 15:44:43
【问题描述】:
我正在尝试构建一个简单的工具来尝试分析如何购买公寓。 DB = POSTGRES
所以模型基本上是:
class Property(models.Model):
address = CharField(max_length = 200)
price = IntegerField()
user = ForeignKey(User) # user who entered the property in the database
#..
#..
# some more fields that are common across all flats
#However, users might have their own way of analysing
# one user might want to put
estimated_price = IntegerField() # his own estimate of the price, different from the zoopla or rightmove listing price
time_to_purchase = IntegerField() # his own estimate on how long it will take to purchase
# another user might want to put other fields
# might be his purchase process requires sorting or filtering based on these two fields
number_of_bedrooms = IntegerField()
previous_owner_name = CharField()
如何为用户提供这样的灵活性?他们应该能够通过这些自定义字段对自己的行(在属性表中)进行排序、过滤和查询。我现在能想到的唯一选择是 JSONField Postgres 字段
有什么建议吗?我很惊讶这在 Django 中没有轻易解决 - 我相信很多其他人已经遇到过这个问题
谢谢
【问题讨论】:
标签: python django database postgresql