`Я хочу отобразить флажок в целях шаблона. html, что я здесь делаю не так?
Models.py
Цель состоит в том, чтобы зафиксировать input Будет набор целей, с которыми должно быть связано 2 флажка
Отметка для флажков
from django.db import models
Будет набор целей, с которыми должно быть связано 2 флажка
# Create your models here.
class GoalModel(models.Model):
Goal=models.CharField(max_length=50)
Check=models.CharField(max_length=50)
def __str__(self):
return self.Goal
views.py
from django.shortcuts import render, HttpResponseRedirect
from .models import GoalModel
from .forms import GoalForm, GoalCheck
# Create your views here.
def index(request):
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = GoalForm(request.POST)
# check whether it's valid:
if form.is_valid():
form.save()
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect('/goals/')
# if a GET (or any other method) we'll create a blank form
else:
form = GoalForm
return render(request, 'index.html', {'form': form})
def goals(request):
`this shows all the goals in the db`
show_goals=GoalModel.objects.all()
'''
if request.method == "POST":
display_type = request.POST.get("display_type", None)
if display_type in ["Done", "Didn't do"]:
return HttpResponseRedirect('/play/')
'''
if request.method == "POST":
form_check = GoalCheck(request.POST or None)
# Have Django validate the form for you
if form_check.is_valid():
# The "display_type" key is now guaranteed to exist and
# guaranteed to be "displaybox" or "locationbox"
display_type = request.POST["display_type"]
if display_type in ["Done", "Didn't do"]:
return HttpResponseRedirect('/play/')
else:
form_check = GoalCheck(request.POST or None)
# This will display the blank form for a GET request
# or show the errors on a POSTed form that was invalid
zipped=list(zip(show_goals, form_check))
return render(request, 'goals.html', {'show_goals': show_goals,
'form_check':form_check, 'zipped':zipped})
Я пытаюсь отобразить GoalCheck, я думаю, что ошибка возникает из
forms.py
from django import forms
from .models import GoalModel
from django.forms import ModelForm
DISPLAY_CHOICES = [(
("DoneBox", "Done is"),
("Didn'tDoBox", "Didn't Do is")
)]
class GoalForm(forms.ModelForm):
class Meta:
model=GoalModel
fields=['Goal',]
class GoalCheck(forms.ModelForm):
category = forms.ChoiceField(widget=forms.RadioSelect(), choices=DISPLAY_CHOICES)
class Meta:
model=GoalModel
fields=['Goal', 'Check','category']
index. html
<center>
<h2>What do you want to do everyday</h2>
<form method="post">
{% csrf_token %}
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }} {{ field }}
{% if field.help_text %}
<p class="help">{{ field.help_text|safe }}</p>
{% endif %}
</div>
{% endfor %}
<input type="submit" value="Submit" />
</form>
</center>
голов. html
<center>
<h2>What did you do today?</h2>
<form method='post'>
{% csrf_token %}
{% for goals in show_goals %}
<p>{{goals}}</p>
{% endfor %}
<input type="submit" value="Submit" />
{{form_check.as_p}}
</form>
I tried rendering the checkbox and it gave me this error: Too many values to unpack (expected 2) in Django please what am i doing wring here?