Задать вопрос

Тел: +7 965 3737 888

451

Просмотров

1

Ответов

PatchModelForm - A ModelForm subclass with the semantics of the PATCH HTTP method

<p>Use this class to partially update one or more fields of a model. Only the fields that are bound to the form via the "data" parameter in the constructor get updated. All automatically generated fields have their "required" attribute set to False.</p>
<p>Example 1:</p>
from django.contrib.auth.models import User

class PatchUserForm(PatchModelForm):
    class Meta:
        model = User

user = User.objects.get(username='old_username')
form = PatchUserForm(data={'username':'new_username'}, instance=user)
form.is_valid()
form.save()

<p>Example 2:</p>
from django.contrib.auth.models import User

class PatchUserForm(PatchModelForm):
    class Meta:
        model = User

user = User.objects.get(pk=35)
form = PatchUserForm(data={'last_name':'Smith', 'is_staff': True}, instance=user)
form.is_valid()
form.save()

Вопрос полезен? Да0/Нет0
file_3485.py(2.4Кб)
None

Ответы (1):

Ответumbrae:28.05.2012
Ответ полезен? Да0/Нет0

On line 12 you have UpdateModelForm - I assume that's meant to be PatchModelForm.