我的模板中有以下内容
{% for excursion in excursions %}
{{ excursion.pk }}-{{ formset.excursion.value }},
<input type="radio" id="id_excursion_{{ excursion.pk }}" name="excursion" value="{{ excursion.pk }}"{% if formset.excursion.value == excursion.pk %} checked="checked"{% endif %} />
<label for="id_excursion">{{ excursion.name }}</label>
{{ excursion.short|safe|linebreaksbr }}
</div>
{% endfor %}
template print: 1-1,1-3,
formset.excursion.value is 1
excursion.pk = 1 and 3 (2 objects)
我的观点:
def edit(request, uuid):
confirm = None
instance = get_object_or_404(Foo, uuid=uuid)
formset = FooForm(instance=instance)
excursions = Excursion.objects.filter(is_activity=False)
context = {
'excursions':excursions,
'formset':formset,
}
if request.method == "POST":
formset = FooForm(request.POST, request.FILES, instance=instance)
if formset.is_valid():
form = formset.save()
confirm = 'true'
context = {
'excursions':excursions,
'formset':formset,
'confirm_create':confirm
}
return render(request, "edit.html", context)
当我导航到这个页面时,它应该是这样,但是当我提交表单,并在提交后再次呈现页面时,它不会再次返回TRUE,即使值仍然存在,也是如此前?
我想也许是因为一个值是字符串而另一个是int?但是,在将值放入引号
时,这似乎没有什么区别我甚至尝试了 ifequal标签,但它做了相同的