2π
β
how would I first create, then update all of this, before finally saving
These arenβt separate steps. When you create or update a record in Django, you are saving it to the database.
For the registration form, Iβd recommend you set it up as a ModelForm
on User
records, then specify the additional fields you want to save to the profile and save them separately in the save function, like soβ¦
class RegistrationForm(forms.ModelForm):
location = forms.CharField(max_length=100)
# etc -- enter all the forms from UserProfile here
class Meta:
model = User
fields = ['first_name', 'last_name', 'email', and other fields in User ]
def save(self, *args, **kwargs):
user = super(RegistrationForm, self).save(*args, **kwargs)
profile = UserProfile()
profile.user = user
profile.location = self.cleaned_data['location']
# and so on with the remaining fields
profile.save()
return profile
π€Jordan Reiter
0π
You could call profile.user.save() and after it profile.save() when you need to save data from registration form.
π€dbf
- [Answered ]-Many-to-many fields with intermediate tables must not be symmetrical
- [Answered ]-Django/Haystack β best option to have a listview with search capability
Source:stackexchange.com