English 中文(简体)
django模型格式_要素-管理表格数据缺失
原标题:django modelformset_factory - management form data is missing
  • 时间:2012-04-24 17:50:18
  •  标签:
  • django
  • forms

我仍在用表格进行战斗,我完全明白我为什么会发现这一错误:

u 管理 表格数据缺失或被篡改。

Thats my code: Please point out my mistakes and help me with resolving this issue.

@csrf_protect
@transaction.commit_on_success
def signup(request):
    form = NewUserCreationForm()
    doc_form = NewDocRegisterForm()

    SpecialityLicensesFormSet = modelformset_factory(SpecialityLicenses, extra=1, exclude = ( user ))
    formset = SpecialityLicensesFormSet(queryset=SpecialityLicenses.objects.none())

    if request.method == "POST":

        form = NewUserCreationForm(request.POST or None)
        doc_form = NewDocRegisterForm(request.POST or None)
        formset = SpecialityLicensesFormSet(request.POST or None)


        if form.is_valid() and doc_form.is_valid() and formset.is_valid():

            user = form.save()

            doc = doc_form.save(commit=False)
            doc.user = user
            doc.save()



            print formset
            fset = formset.save(commit=False)

            for n in fset:
                n.user = user
                n.save()

            return HttpResponse("Uzytkownik utowrzony")

    return render_to_response("userena/signup_new.html", { form : form,
                                                           doc_form : doc_form,
                                                           spec_form : formset,}, 
                              context_instance=RequestContex

t(request)) 

模板代码:

<form action="/en/accounts/doc_register/" method="post">{% csrf_token %}
    {% for field in form %}


    <div>
        {% if field.errors %}
            {{ field.errors|striptags }} |
        {% endif %}

        {{field.label}} | {{ field}}
    </div>


    {% endfor %}

    <hr>


    {% for f in doc_form %}
    <div>
    {% if f.errors %}
    {{f.errors|striptags}} | 
    {% endif %}

    {{f.label}} : {{ f }}
    </div>
    {% endfor %}
    <hr>

    {{ spec_form.management_form }}
    {{ spec_form }}

            <hr>
    <input type="submit" value="Submit"/>
</form>
{% endblock %}
最佳回答

如果您填写了<条码>{表格>,则无需填写。

{{ formset.management_form }}
{% for form in formset %}
  {{ form }}
{% endfor %}

试图从你的模板中删除<代码>{spec_form. management_form <>/code>。 http://docs.djangoproject.com/en/dev/topics/forms/formsets/#using-a-formset-in-views-and-templates” 第三例:

问题回答

add prefix for formset if prefix is missing for formset it will give error





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签