我有几个看起来像这样的模型:
class System(models.Model):
'''Defines a system'''
system_desc = models.CharField('System Name', max_length=50)
class SystemGroup(models.Model):
'''Groups within a 'System' (ie. Customers, regions, divisions, etc. '''
group_desc = models.CharField('Group Name',max_length=25)
system = models.ForeignKey(System)
class QueryData(models.Model):
'''Queries related to a 'System' (ie. Active users against System1, Orders today in system2, etc. '''
qry_desc = models.CharField('Query Description', max_length=50)
system = models.ForeignKey(System)
class UserDashboard(models.Model):
'''User specific Dashboard '''
user = models.ForeignKey(User)
board_name = models.CharField('Dashboard Name', max_length=50)
class UserDashboardGroup(models.Model):
'''Groups on the dashboard (ie. 'System 1's Key Indicators', 'System 2's Hot Sheet', etc. '''
group_desc = models.CharField('Group Display Title', max_length=50)
user = models.ForeignKey(User)
dashboard = models.ForeignKey(UserDashboard)
system = models.ForeignKey(System)
system_group = models.ForeignKey(SystemGroup)
class UserGroupQuery(models.Model):
'''Queries that run in a specific group on the dashboard (ie. Within 'System 1's Key Indicators, we run queries for active users today, orders in the last hour, etc. '''
user = models.ForeignKey(User)
dashboard = ChainedForeignKey(UserDashboard, chained_field='user', chained_model_field='user', show_all=False, auto_choose=True)
user_dashboard_group = ChainedForeignKey(UserDashboardGroup, chained_field='dashboard', chained_model_field='dashboard')
query = models.ForeignKey(QueryData)
我在最后一部分遇到问题。我想限制基于选定的管理页面中显示的“查询” user_dashboard_group
。不过,根据我目前的模型,我不确定如何做到这一点。query
并且user_dashboard_group
两者都有一个外键System
,但彼此没有。不过,要得到这个,我必须得到user_dashboard_group
'ssystem
然后用它来过滤QueryData
. 我怎样才能做到这一点?
编辑 我正在添加图片以(希望)更好地描述我想要做的事情。在步骤 1 中,用户输入这组查询的名称。该组与系统 (#2) 和系统内的预定义组 (#3) 相关联(将 #3 视为“客户”或“区域”等,而 #1 和 #3 不是一回事,尽管命名相似)。然后,他们在此内联表单上选择“保存并继续编辑”,第 4 步的下拉菜单将填充来自上述表单的信息。一旦第 4 步进行了选择,我希望第 5 步仅填充来自关联系统的数据。由于#2 包含此信息,我希望这样做相当容易,但我无法弄清楚链接。
我也意识到我没有提到我正在使用django-smart-selects