class SinglePoint(models.Model):
attributes = models.TextField(blank=True)
name = models.CharField(max_length=100)
geom = models.PointField() #Kartenposition
objects = models.GeoManager()
class Connection(models.Model):
name = models.CharField(max_length=100)
#points = models.ManyToManyField(SinglePoint) #OLD
p1 = models.ForeignKey(SinglePoint, related_name='p1_set') #NEW
p2 = models.ForeignKey(SinglePoint, related_name='p2_set') #NEW
obs = models.ManyToManyField(Observation, blank=True)
conds = models.ManyToManyField(Condition, blank=True)
objects = models.GeoManager()
class Meta:
order_with_respect_to = 'p1'
在我view.py:
...
p1_points = SinglePoint.objects.filter(p1_set__vektordata__order__project__slug=slug)
p2_points = SinglePoint.objects.filter(p2_set__vektordata__order__project__slug=slug)
...
之前,我切换到外键,它的工作有:
points = SinglePoint.objects.filter(connection__vektordata__order__project__slug=slug)
如何“加入”这两个查询集到一个查询集,并作出不同的()?
谢谢!