我正在设计一个叫做“Clothes”的简单Django模型。基本上它检索用户拥有什么样的衣服。我将衣服分为20多种(例如连帽衫,牛仔裤,裤子)和三大类:“上衣”,“下装”,“鞋子”。你能建议更好的Django模型设计吗? (我是Django初学者)
在“ClothesView”中,我想为每个“顶部”,“底部”,“鞋子”显示前5件衣服。 而将获取5个单项类别,如果用户点击更多的(所以,如果用户点击“更多的顶级”,它将返回“顶”型的5件衣服。
为了您更好的了解,我写了“衣服的模型概念。
class Clothes(models.Model):
id
type = # hoodie, shirts, pants, jean, coat, and so on (more than 20)
big_type = # top, bottom and shoes
owner = ForeignField # some one who post
预期输出(这只是我的猜测!)
检索5件衣服每个parent_types( “顶”, “底”, “鞋”)
user.clothes_set.filter(big_type="top")[:5] user.clothes_set.filter(big_type="bottom")[:5] user.clothes_set.filter(big_type="shoes")[:5]
检索5件衣服 “顶”
user.clothes_set.filter(big_type="top)[5:10]
检索所有从我的衣服< “帽衫” - 这看起来不错
user.clothes_set.filter(type="hoodies")
您能否提供更好的高效模式?我可以添加新的类型类,并把“通过”...(我不知道)