Created
July 10, 2019 01:32
-
-
Save Drunpy/555e4e95cf1b4639abf74d4ba3ee8195 to your computer and use it in GitHub Desktop.
Polimorphism example using Django's ModelForm
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
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