Last active
April 13, 2020 09:58
-
-
Save jqn/90545f532cdbc27e375269c7084078f6 to your computer and use it in GitHub Desktop.
SuperTuber TutorUserSignUpForm
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
| class TutorUserSignUpForm(forms.ModelForm): | |
| def __init__(self, *args, **kwargs): | |
| self.user = kwargs.pop('user', None) | |
| super(TutorUserSignUpForm, self).__init__(*args, **kwargs) | |
| self.helper = FormHelper(self) | |
| profile = Profile.objects.get(pk=self.user.pk) | |
| self.initial['firstname'] = profile.firstname | |
| self.initial['lastname'] = profile.lastname | |
| class Meta: | |
| model = TUser # change model to TutorProfile and add bio | |
| fields = ['username', 'firstname', 'lastname', | |
| 'email', 'phone_number', 'subjects', 'image'] | |
| widgets = { | |
| 'username': forms.TextInput( | |
| attrs={ | |
| 'class': 'form-control', | |
| } | |
| ), | |
| 'firstname': forms.TextInput( | |
| attrs={ | |
| 'class': 'form-control', | |
| 'value': "Hello world" | |
| } | |
| ), | |
| 'lastname': forms.TextInput( | |
| attrs={ | |
| 'class': 'form-control' | |
| } | |
| ), | |
| 'email': forms.EmailInput( | |
| attrs={ | |
| 'class': 'form-control' | |
| } | |
| ), | |
| 'phone_number': forms.NumberInput( | |
| attrs={ | |
| 'class': 'form-control' | |
| } | |
| ), | |
| 'subjects': forms.Select( | |
| choices=SUBJECT_CHOICES, | |
| attrs={ | |
| 'class': 'form-control' | |
| } | |
| ), | |
| 'image': forms.ClearableFileInput( | |
| attrs={ | |
| 'class': 'form-control' | |
| } | |
| ), | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your views also need to be updated
Basically I'm passing the logged-in user to the form in forms.py