我有一個帖子(自我),我想添加一些邏輯來添加lat和lng(這些都是從谷歌地圖計算)到我的數據存儲中定義的db模型。我應該添加到數據中,還是應該像原始類一樣以其他方式進行操作?做這個的最好方式是什麼?訪問谷歌應用程序引擎中的後置過程中的字段
所以......
class Company(db.Model):
company_type = db.StringProperty(required=True, choices=["PLC", "LTD", "LLC", "Sole Trader", "Other"])
company_lat = db.StringProperty(required=True)
company_lng = db.StringProperty(required=True)
class CompanyForm(djangoforms.ModelForm):
company_description = forms.CharField(widget=forms.Textarea(attrs={'rows':'2', 'cols':'20'}))
company_address = forms.CharField(widget=forms.Textarea(attrs={'rows':'2', 'cols':'20'}))
class Meta:
model = Company
exclude = ['company_lat,company_lng']
def post(self):
data = CompanyForm(data=self.request.POST)
map_url = ''
address = self.request.get("company_postcode")
...
lat = response['results'][0]['geometry']['location']['lat']
lng = response['results'][0]['geometry']['location']['lng']
...
# How do I add these fields lat and lng to my data store?
# Should I add them to data? if this is possible?
# Or shall I do it some other way?
感謝
@DrewSears保存之前添加字段,因爲我沒有編輯權限,我不能編輯問題,移動'Meta'類中'CompanyForm'類,因爲它應該根據[Google App Engine djangoforms幫助頁面](http://code.google.com/intl/fi-FI/appengine/articles/djangoforms.html)。 – 2011-05-19 20:38:36
對不起,我的錯,固定。 – 2011-05-19 21:11:19