repsheetを見てみる
GeoDjangoのチュートリアルも一応終え、GeoDjangoを使ったrepsheetのソースを見てみます。
稼動しているサイトはhttp://repsheet.comです。
まずはmodels.pyを見てみる(一部抜粋)。
from django.contrib.gis.db import models from django.contrib.localflavor.us.models import PhoneNumberField, USStateField class Boundary(models.Model): CLASS_CHOICES=( ('stbr', 'StateBoundary'), ('ctbr', 'CityBoundary'), ('nycb', 'NYCityBoundary')) class_type = models.CharField(max_length=4, choices=CLASS_CHOICES, db_index=True) BTYPE_CHOICES = () bnd_type = models.CharField(max_length=3, choices=BTYPE_CHOICES, db_index=True) district = models.PositiveIntegerField() state = USStateField() geom = models.GeometryField() def get_pboundary(self): if self.class_type == 'stbr': return self.stateboundary elif self.class_type == 'ctbr': return self.cityboundary elif self.class_type == 'nycb': return self.cityboundary.nycityboundary def save(self, force_insert=False, force_update=False): self.class_type = self.get_class_type() super(Boundary, self).save(force_insert, force_update) class StateBoundary(Boundary): BTYPE_CHOICES = ( ('sen', 'senate'), ('hou', 'house'), ('cng', 'congress')) def get_class_type(self): return 'stbr' class CityBoundary(Boundary): BTYPE_CHOICES = (('wrd', 'Ward'),) city = models.CharField(max_length=200,) def get_ward_label(self): return 'Ward' def get_class_type(self): return 'ctbr' class NYCityBoundary(CityBoundary): BTYPE_CHOICES = CityBoundary.BTYPE_CHOICES + ( ('bor', 'borough'), ('com', 'community')) def get_ward_label(self): return 'City Council' def get_class_type(self): return 'nycb'
継承が参考になる。
うーん、Adminで見たとき"bnd_type"がコンボボックスになると思っていたんだけどならないのは何故?
おれの思い違い?写経ミスかな?