我正在尝试创建由计划提供者订购的医生接受的保险计划列表。如何构造一个查询,使我能够生成如下结果列表:
Provider 1
Plan A
Plan B
Plan C
Provider 2
Plan D
Provider 3
Plan E
Plan F
给定以下(简化的)模型:
class Provider(models.Model):
name = models.CharField(_('Name'), max_length=50)
class Plan(models.Model):
name = models.CharField(_('Name'), max_length=50)
provider = models.ForeignKey(Provider)
class DoctorProfile(UserProfile):
accepted_insurance_plans = models.ManyToManyField(Plan, blank=True)