Created
December 8, 2011 11:26
-
-
Save saketkc/1446763 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class NewReportTypeForm(forms.ModelForm): | |
def __init__(self, *args, **kwargs): | |
self.report_belongs_to_lab = kwargs.pop('report_belongs_to_lab', None) | |
super(NewReportTypeForm, self).__init__(*args, **kwargs) | |
def save(self, commit=True): | |
instance = super(NewReportTypeForm, self).save(commit=False) | |
if self.report_belongs_to_lab: | |
instance.report_belongs_to_lab = self.report_belongs_to_lab | |
return instance.save() | |
class Meta: | |
model = ReportTypes | |
exclude = ('report_belongs_to_lab') #Dont include it in the form ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment