我正在設計一個叫做「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")
您能否提供更好的高效模式?我可以添加新的類型類,並把「通過」...(我不知道)