Skip to content

Instantly share code, notes, and snippets.

@chriskief

chriskief/modelform.py

Last active Dec 26, 2015
Embed
What would you like to do?
from django import forms
from django.forms import ModelForm
from app.models.author import Author
class UpdateAuthorForm(ModelForm):
name = forms.CharField(
max_length=Author._meta.get_field('name').max_length
)
def save(self, commit=True):
instance = super(UpdateAuthorForm, self).save(commit=False)
if commit:
# save
instance.save(update_fields=['name'])
return instance
class Meta:
model = Author
fields = ('name',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.