半径100マイル以内Records
にあるを見つけたいです。tag
独立して動作する 2 つのクエリがありますが (以下を参照)、それらを組み合わせる方法がわかりません。
また、モデルには、 というモデルRecords
を指す外部キーがあります。モデルと) の両方のフィールドをワンショットで表示できるようにしたい。以下のクエリを試してみましたが、何らかの理由でモデル フィールドのみが表示され、追加のモデル フィールドは表示されません。GeoLocation
geo_location
(Records
GeoLocation
.select_related()
GeoLocation
GeoLocation
Records
tag_search = Records.objects.filter(tags__slug__in=[tag])
geo_search = GeoLocation.objects.select_related().filter(srid2163__distance_lte=(pnt, D(mi=100))).distance(pnt)
何か案は?
これらは私のモデルです:
from taggit.managers import TaggableManager
from django.contrib.gis.db import models
class GeoLocation (models.Model):
lat = models.FloatField(blank=True)
long = models.FloatField(blank=True)
srid2163 = models.PointField(blank=True,srid=2163)
server_time = models.DateTimeField(auto_now_add=True)
objects = models.GeoManager()
def __unicode__(self):
return u'%s %s %s' % (self.lat, self.long, self.server_time)
class Records(models.Model):
title = models.CharField(blank=True, max_length=50)
message_body = models.TextField()
server_time = models.DateTimeField(auto_now_add=True)
geo_location = models.ForeignKey(GeoLocation, related_name='geoloc')
tags = TaggableManager()
def __unicode__(self):
return u'%s %s %s' % (self.title, self.message_body, self.server_time)
モデルのtags
フィールドにはdjango-taggitを使用しています。Records