Re: creating user and profile in just one form
I suppose that you should also check if the username isn't already taken. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: creating user and profile in just one form
Joe ha scritto: > I've done this but with a manually built form. > > You can just add the extra form fields to the template, then reference > those extra fields in your view. > Yes, after trying with inline options to no result, I've resolved too in using the fields instead of the form to have more granularity : This is the template : [..] Password: {{ f_user.password }} Clid: {{ f_customer.clid }} [..] And the view: [..] if request.method == 'POST': user = User(username=request.POST['username']) user.set_password(request.POST['password']) user.save() customer = CustomerProfile(user=user, clid=request.POST['clid']) customer.save() [..] It's not that inelegant in the end ... probably it can get better with the fields meta-option of ModelForm > j > > On Dec 10, 5:15 am, Simone Cittadini <[EMAIL PROTECTED]> wrote: > >> I have this code to add a new user : >> >> class CustomerForm(ModelForm): >> >> class Meta: >> model = CustomerProfile >> >> def add(request): >> [..] >> if request.method == 'POST': >> form = CustomerForm(customer, request.POST) >> f.save() >> else: >> form = CustomerForm(customer) >> return render_to_response('customer/add.html', locals(), >> RequestContext(request, {})) >> [..] >> >> which automagically creates a web form where you choose among existing >> users as one of the CustomerProfile fields. >> >> Now since my app as to be (subnormal)user-friendly I want the code to >> render just one form with name/password fields among the profile ones, >> and no existing users choice-list, is it possible ? >> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: creating user and profile in just one form
I've done this but with a manually built form. You can just add the extra form fields to the template, then reference those extra fields in your view. new_data['your_new_fieldname'] will work as expected. In your view you might first create the user object - then create the customer object related to the newly created user object: user = User.objects #create the new user account user.save() later on in the same view function for the customer: new_data['user'] = str(user.id) #new user from above j On Dec 10, 5:15 am, Simone Cittadini <[EMAIL PROTECTED]> wrote: > I have this code to add a new user : > > class CustomerForm(ModelForm): > > class Meta: > model = CustomerProfile > > def add(request): > [..] > if request.method == 'POST': > form = CustomerForm(customer, request.POST) > f.save() > else: > form = CustomerForm(customer) > return render_to_response('customer/add.html', locals(), > RequestContext(request, {})) > [..] > > which automagically creates a web form where you choose among existing > users as one of the CustomerProfile fields. > > Now since my app as to be (subnormal)user-friendly I want the code to > render just one form with name/password fields among the profile ones, > and no existing users choice-list, is it possible ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
creating user and profile in just one form
I have this code to add a new user : class CustomerForm(ModelForm): class Meta: model = CustomerProfile def add(request): [..] if request.method == 'POST': form = CustomerForm(customer, request.POST) f.save() else: form = CustomerForm(customer) return render_to_response('customer/add.html', locals(), RequestContext(request, {})) [..] which automagically creates a web form where you choose among existing users as one of the CustomerProfile fields. Now since my app as to be (subnormal)user-friendly I want the code to render just one form with name/password fields among the profile ones, and no existing users choice-list, is it possible ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---