python - Multiple Choice with fixed options. Dont see the options (Django) -
i'm new django , i'm trying make select several choices field, seem having problems that
here simplified version of model site
class zone(models.model): zone = ( ('ne','northeast'), ('se','southeast'), ('sw','southwest'), ('mw','midwest'), ('cn','canada'), ) class site(models.model): region = models.manytomanyfield(zone) state = models.charfield(max_length = 30) ... class siteform(modelform): class meta: model = site
now, there more zones i'm showing here , potentially means site may have several zone simultaneously.
simple view function:
def add_site(request): if request.method == 'post': form = siteform(request.post) if form.is_valid(): profile = form.save(commit=false) profile.user = request.user profile.save() else: form = siteform() return render(request, 'index.html', {'form': form,})
it understanding once form on webpage, should presented box choices specified in zone class, box empty. how populate choices such northwest, southeast, southwest, etc?
this isn't quite how works. check out this definition in django documentation. example pretty clear, trying strange.
i suspect trying create separate model choices - use modelchoicefield or modelmultiplechoicefield - define zone model actual model; have isn't django model @ all.
in addition "site" django-provided model - should okay, can run hard-to-diagnose problems if you're using django contributed auth.
Comments
Post a Comment