Login

Tag "patch"

Snippet List

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

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. Example 1: 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() Example 2: 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()

  • models
  • rest
  • update
  • patch
  • partial-update
Read More

Testserver: --noinput option, sending a signal

Makes manage.py testserver accept a `--noinput` argument to delete test database without asking if it already exists; makes it emit `django.core.management.commands.testserver.testserver_setup` signal after fixtures are loaded and before server itself is started to allow custom postprocessing.

  • django
  • patch
  • testserver
Read More

3 snippets posted so far.