我需要一种方法来获取相关行和不相关行的列表,例如列表,我在其中搜索 FenceGroup 并获取所有与 Fence 相关且不相关的行,其中非相关显示为“无”或类似内容,原因,我需要用它实现一个选择列表
我的模型是
class Fence (ModelBase):
FENCES_TYPES = (
(1, 'Circle'),
(2, 'Polygon'),
(3, 'Polyline'),
(4, 'Rectangle'),
)
name = models.CharField(max_length=128)
description = models.TextField(null=True, blank=True)
fence_type = models.IntegerField(choices=FENCES_TYPES, default=1)
color = models.CharField(max_length=6)
radius = models.FloatField(null=True, blank=True)
points = models.TextField(null=True, blank=True)
status = models.BooleanField(default=True)
def __unicode__(self):
return self.name
class Meta:
db_table = 'gpstracking_fences'
class FenceGroup (ModelBase):
FENCES_TYPES = (
(1, 'Circle'),
(2, 'Polygon'),
(3, 'Polyline'),
(4, 'Rectangle'),
)
fence_group = models.ManyToManyField(Fence, through='FenceShip')
name = models.CharField(max_length=128)
description = models.TextField(null=True, blank=True)
def __unicode__(self):
return self.name
class Meta:
db_table = 'gpstracking_fence_groups'
class FenceShip(ModelBase):
fence_group = models.ForeignKey(FenceGroup)
fence = models.ForeignKey(Fence)
class Meta:
db_table = 'gpstracking_fence_ships'