Created
January 5, 2012 11:11
-
-
Save jsanchezpando/1564775 to your computer and use it in GitHub Desktop.
pre-set values before model form saving
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import forms | |
from myapp.models import MyObject | |
class MyObjectForm(forms.ModelForm): | |
class Meta: | |
model = MyObject | |
def save(self, commit=True): | |
o = super(MyObjectForm, self).save(commit=False) | |
# o.value = "pre-set value fi user" | |
if commit: | |
o.save() | |
return o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment