Skip to content

Instantly share code, notes, and snippets.

@Drunpy
Created July 10, 2019 01:32
Show Gist options
  • Save Drunpy/555e4e95cf1b4639abf74d4ba3ee8195 to your computer and use it in GitHub Desktop.
Save Drunpy/555e4e95cf1b4639abf74d4ba3ee8195 to your computer and use it in GitHub Desktop.
Polimorphism example using Django's ModelForm
class QuotationForm(forms.ModelForm):
class Meta:
model = Quotation
fields = ('client','date_create', 'date_update', 'house_type',
'house_set',
)
def __init__(self, *args, **kwargs):
self.request = kwargs.get('request')
super().__init__()
def save(self, *args, **kwargs):
# A parte importante
self.cleaned_data['client'] = self.request.user
super().save(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment