我有下面这三个模型,我想要实现以下目标:
models.py
class Owner(models.Model):
GENDER_CHOICES = (
('Male', 'Male'),
('Female', 'Female'),
)
MARITAL_STATUS_CHOICES = (
('Single', 'Single'),
('Married', 'Married'),
('Widowed', 'Widowed'),
('Divorced', 'Divorced'),
)
user= models.OneToOneField(User)
spersonid = models.ForeignKey(Information)
ctin = models.CharField("TIN",max_length=50)
csss = models.CharField("SSS", max_length=50)
crescertificate = models.CharField("Res. Certificate", max_length=50)
cgender = models.CharField("Gender", max_length=10, choices=GENDER_CHOICES, null=True, blank=True)
cmaritalstatus = models.CharField("Marital Status", max_length=50, choices=MARITAL_STATUS_CHOICES, null=True, blank=True)
User.profile = property(lambda u: Owner.objects.get_or_create(user=u)[0])
def __unicode__(self):
return self.spersonid.cfirstname
class ButuanMaps(gismodel.Model):
class Meta:
verbose_name = u'Butuan Map'
verbose_name_plural = u'Butuan Maps'
clandpin = gismodel.CharField("Land PIN", max_length=50, null=True, blank=True)
ssectionid = gismodel.ForeignKey(Section)
#ssectionid_id = gismodel.IntegerField()
geom = gismodel.MultiPolygonField("Geom ID", srid=32651, null=True, blank=True)
objects = gismodel.GeoManager()
def __unicode__(self):
return self.clandpin
class LandProperty(models.Model):
DEFAULT_OWNER_ID = 5
class Meta:
verbose_name = u'Land Property'
verbose_name_plural = u'Land Properties'
ctaxdec = models.CharField("Tax Declaration", max_length=50, null=True, blank=True)
sgeomid = models.ForeignKey(ButuanMaps)
sownerid = models.ForeignKey(Owner, default=DEFAULT_OWNER_ID)
clotno = models.CharField("Lot Nos.", max_length=50, null=True, blank=True)
iblockno = models.IntegerField("Block Nos.", null=True, blank=True)
csurveyno = models.CharField("Survey Nos.", max_length=50, null=True, blank=True)
cstreet = models.CharField("Street", max_length=50, null=True, blank=True)
nfrontage = models.CharField("Frontage", max_length=50, null=True, blank=True)
nkmstoweather = models.FloatField("Kms. to Weather", null=True, blank=True)
nkmstomarket = models.FloatField("Kms. to Market", null=True, blank=True)
cnorth = models.CharField("North", max_length=50, null=True, blank=True)
csouth = models.CharField("South", max_length=50, null=True, blank=True)
ceast = models.CharField("East", max_length=50, null=True, blank=True)
cwest = models.CharField("West", max_length=50, null=True, blank=True)
def __unicode__(self):
return self.sgeomid.clandpin
views.py
def display_agao(request, ):
search_term = request.GET.get("q", None)
#query_agao = ButuanMaps.objects.filter(clandpin=search_term)
x = Owner.objects.select_related('landproperty_butuanmaps').get(id=5)
query_agao = x.landproperty_set.all()
query_all = ButuanMaps.objects.all()
djf = Django.Django(geodjango='geom', properties=['id', 'clandpin'])
geoj = GeoJSON.GeoJSON()
butuan_agao = geoj.encode(djf.decode(query_agao.transform(3857)))
return render(request, "index.html", {
'butuan_agao': butuan_agao,
'query_agao': query_agao,
'query_all': query_all})