Резюме:
У меня есть 1 ко многим иерархическим отношениям между моделями
Страна (1) -> Город (Много)
Город (1) -> Статус (Много)
У меня есть форма для печати полей, принадлежащих всем этим моделям, но когда я печатаю, я вижу только поле «город», и оно также отображается в виде раскрывающегося списка, а не в виде текстового поля. Я пытался найти эту проблему, но решения не появились.
Выдержка из кода:
from google.appengine.ext import db
from google.appengine.ext.db import djangoforms
class UserReportedCountry(db.Model):
#country selected by the user
country_name = db.StringProperty( required=True,
choices=['Afghanistan','Aring land Islands']
)
class UserReportedCity(db.Model):
country = db.ReferenceProperty(UserReportedCountry, collection_name='cities')
city_name = db.StringProperty(required=True)
class UserReportedStatus(db.Model):
city = db.ReferenceProperty(UserReportedCity, collection_name='statuses')
status = db.BooleanProperty(required=True)
date_time = db.DateTimeProperty(auto_now_add=True)
class UserReportedDataForm(djangoforms.ModelForm):
class Meta:
model = UserReportedStatus
exclude = ('status’ )
Спасибо
[EDIT # 1]
Я случайно наткнулся на этот пост ( как создавать динамически сгенерированные формы с отношениями один-ко-многим в django ) и следовал методу, который податель использовал для печати форм на странице
A] Формы в классе модели сейчас
class UserCountryForm(djangoforms.ModelForm):
class Meta:
model = UserReportedCountry
class UserCityForm(djangoforms.ModelForm):
class Meta:
model = UserReportedCity
exclude = ('country', )
class UserStatusForm(djangoforms.ModelForm):
class Meta:
model = UserReportedStatus
#hiding the site_is_up property
exclude = ('site_is_up', 'city' )
B] Метод, который печатает эти формы:
def print_user_reporting_form(self):
self.response_variable.out.write('<div id="userDataForm">'
'<form method="POST" '
'action="/UserReporting">'
'<table>' )
#method call to print the pre-populated user form with users country and city value
self.response_variable.out.write (UserCountryForm())
self.response_variable.out.write (UserCityForm())
self.response_variable.out.write(UserStatusForm())
self.response_variable.out.write ( '</table>'
'<input type="submit" name="report_up" value= "Report Up">'
'<input type="submit" name="report_down" value= "Report Down">'
'</form>'
'</div>')
Спасибо,