[英]Boolean attribute or new table (Django + PostgreSQL)
Situation: I have a Books set. 情况:我有一套书。 Book can be one of the types: "Test", "Premium" and "Common".
图书可以是以下类型之一:“测试”,“高级”和“普通”。 Data proportional: 2%, 15%, 83%.
数据比例:2%,15%,83%。 Amount query per time unit (in percent): 40%, 20%, 40%
每个时间单位的查询量(百分比):40%,20%,40%
I see some ways for resolve it in database: 我看到一些解决数据库中问题的方法:
Book.objects.filter(is_test=True)
. Book.objects.filter(is_test=True)
。 It is can be a proxy model, for example. ['Test', 'Premium', 'Common']
; ['Test', 'Premium', 'Common']
字符串; And we need optimally querying this data! 我们需要以最佳方式查询此数据! All three Book variants need in one page.
所有这三种Book变体都需要一页。 Exist queryset combinations: only tests, only common, common + premium, only premium.
现有查询集组合:仅测试,仅通用,通用+高级,仅高级。
Which way is more correct and why? 哪种方法更正确,为什么?
If you need to mix different types on one page, separate models/tables would complicate things for no good reason. 如果您需要在一页上混合使用不同的类型,则没有充分的理由将单独的模型/表复杂化。 The same goes for mapping more than two exclusive states to a combination of boolean fields.
将两个以上的互斥状态映射到布尔字段的组合也是如此。
This leaves you with a choice field or a separate BookType
model containing the choices. 这样就为您提供了一个选择字段或一个包含选择的单独
BookType
模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.