【问题标题】:How to model my database relationships如何建模我的数据库关系
【发布时间】:2016-11-10 10:49:45
【问题描述】:

我在这个论坛上进行了很多搜索,并且在在这里发布我的问题之前还浏览了文档,我正在开发一个时尚聚合网站来展示服装,目前我正在从不同的网站抓取我的产品并将其存储在 csv 文件中.我的 CSV 有这样的标题
(标题描述pricell类别子类别颜色模式)。如何设计我的 django 模型以具有类似此网页https://lookastic.com/men/light-blue-vertical-striped-short-sleeve-shirt 的功能,您可以在其中查看是否选择了一个类别属于该类别的所有颜色如下所示,如果选择了一种颜色,如果该颜色有任何图案,那么它会显示在颜色侧边栏下方。如何创建表之间的关系以及我需要根据我的 csv 创建哪些表才能实现此功能?

【问题讨论】:

    标签: django django-models django-admin django-modeladmin


    【解决方案1】:

    看来您还有很多有趣的工作要做!我将为您提供一些有关如何开始的提示。我将从 3 个初学者模型开始使用:

    # This will be where you will store categories like top, footwear etc.
    class Category(models.Model): # probably pick a more clever name
        name = models.CharField()
    
    
    # This is where you would put shirts, jackets etc.
    class SubCategory(models.Model): # again probably pick a better name
        name = models.CharField()
        category = models.ForeignKey('Category')
    
    
    # This is where the actual item would be
    class Item(models.Model):
        name = models.CharField()
        colours = models.CharField() # if you want to make this better, choose it from a list of choices
        pattern = models.CharField() # same as colour
        price = models.DecimalField()
        # etc
        sub_category = models.ForeignKey('SubCategory')
    

    或者,外键可以放置在您想要的任何位置(例如,在 Item 中),但我建议将这些模型分开

    【讨论】:

    • 感谢您的启蒙,这正是我所做的,但这是我卡住的地方,我为项目模型创建了管理员,使用列表过滤器和字段子类别颜色和图案现在如何创建如图所示的装备在链接中,设计师在链接中选择产品和一些属性,我可以在产品管理中类似地过滤它,但过滤后如何将它们添加到装备中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    相关资源
    最近更新 更多