首页 > 解决方案 > Django 模型 - 如何将特定的子组集群映射到它们的专属母组

问题描述

我有 2 个要在 Django 中建模的数据库表

第一个表名为 Groups,仅限于 7 个特定选项,ABCDEF G。我已经这样做了。

第二个表名为 Subgroup,限制为 39 个特定选项,编号为 1 到 39,位于不同大小的集群中。每个集群应该只映射到一个特定的组。我不能搬到这里。

How do I set up the second model to reflect the relationship so that whenever a user chooses, say subgroup option 8, the correct foreign key used refers to B in the example, or whenever choosing subgroup option 29 the foreign key used refers to F? 例如,应该不可能将子组 15 映射到组 G。

假设映射应该是:A:1-5,B:6-13,C:14-16,D:17-20 E:21-26,F:27-30,G:31-35和H:36 -39

标签: djangodjango-models

解决方案


推荐阅读