django - 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
解决方案
推荐阅读
- github-actions - 在 Docker 容器中的 GitHub 操作中运行多种语言版本的测试
- c# - DataTemplate 中嵌套元素样式的动态变化
- javascript - 如何在javascript中实现多个项目计数器?
- java - 每秒在谷歌地图中添加新标记
- iphone - Wordpress 选择文件按钮在 iPhone 上不起作用
- javascript - 资源所有者密码授予“必须是 POST 请求”
- javascript - 登录 Angular 后执行的最后一个函数
- r - 在 R 中进行 NA 清理后,类在 data.frame 中没有变化
- python - DJANGO-用户切换账号问题
- html - 如何在 Django 的模板中读取字典