我有以下内容,
class Company(db.Model):
companyvalid = db.BooleanProperty(required=True)
class AddCompanyForm(djangoforms.ModelForm):
class Meta:
model = Company
exclude = ['companyentrytime']
exclude = ['companylatlong']
但是我无法从存储在数据库中的Django中获取o / p。我也只能在选中复选框时添加记录,但在保存记录时这不会反映在基础表中。最聪明的方法是什么?感谢
class AddCompanyCategoriesHandler(webapp.RequestHandler):
def get(self):
memcache.flush_all()
form_requirements = AddCompanyCategoriesForm()
path = os.path.join(os.path.dirname(__file__), 'addcompanycat.html')
self.response.out.write(template.render(path, {'form': form_requirements}))
def post(self):
form_requirements = AddCompanyCategoriesForm(data=self.request.POST)
if form_requirements.is_valid():
myname = form_requirements.clean_data['categoryname']
entity = form_requirements.save(commit=False)
entity.put()
=============================================== ==========================================
我正在尝试使用BooleanField,但这无法正常工作,服务器发出504错误。这是我的模特。我一直在试验这种BooleanFields格式,但我不确定这与我的模型有什么关系。我的模特是
class Company(db.Model):
companyurl = db.StringProperty(required=True)
companyname = db.StringProperty(required=True)
companydesc = db.TextProperty(required=True)
companyaddress = db.PostalAddressProperty(required=True)
companypostcode = db.StringProperty(required=True)
companyemail = db.EmailProperty(required=True)
companycountry = db.StringProperty(required=True)
companyvalid = db.BooleanProperty()
#companyvalid = db.BooleanField(required=True, label="Check this")
companyentrytime = db.DateTimeProperty(auto_now_add=True)
companylatlong = db.GeoPtProperty()
@property
def catname(self):
return self.companycategory.name
companycategory = db.ReferenceProperty(CompanyCategory, collection_name='compcategory')
以及
class AddCompanyForm(djangoforms.ModelForm):
class Meta:
model = Company
#companyvalid = model.BooleanField(default=False)
exclude = ['companyentrytime']
exclude = ['companylatlong']
所以我的问题是,如果我必须使用这个BooleanField,我应该如何将它放在AddCompanyForm中并且模型中是否应该有一个条目?
答案 0 :(得分:0)
尝试在模型中使用BooleanField(https://docs.djangoproject.com/en/dev/ref/models/fields/#booleanfield)而不是布尔属性?