I know this seems like a too complicated question in Django circles, but I'm afraid to say that I have not yet found a solution to this.
My model is
from djago.... import User
class InfoPersonal(models.Model):
...
person = models.OneToOneField(User)
I tried to override save_model () in the admin definition and also override save () on the form, but nothing works.
If you were to automatically add data to the ForeignKey or OneToOneField column to the model, how would you do it?
def profile_creation_personal(request):
if request.method == 'POST':
form = PersonalForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/done')
else:
form = PersonalForm()
return render_to_response('info/personal/profile_create.html', { 'form': form,})
class PersonalForm(ModelForm):
def save(self, *args, **kwargs):
self.person = request.user
super(PersonalForm, self).save(*args, **kwargs)
class Meta:
model = InfoPersonal
exclude = ('person',)
widgets = {'dateofbirth' : SelectDateWidget()}
source
share