Problem Working with forms.Form

38 views
Skip to first unread message

Teddy McZieuwa

unread,
Dec 6, 2015, 11:33:37 AM12/6/15
to Django users
Hi,
please, I am new to django, I just need to know to save to a database while using 'forms.Form' utility and how does it know which database model to use. I do not want to use the 'forms.ModelForm' because i would like to customize, I don't want django giving me its default style form.
Please I really need help ASAP. Thank you.

Gergely Polonkai

unread,
Dec 6, 2015, 2:54:52 PM12/6/15
to Django users

Hello,

you should use ModelForm; if the only problem you have is the CSS properties, you may assign custom CSS classes to your widgets, and use templates to render your fields individually.

Best,
Gergely

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b0474e0d-4cac-4b6f-8396-87208d4e0dc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sum abiut

unread,
Dec 6, 2015, 11:47:50 PM12/6/15
to django...@googlegroups.com
You can use modelForm.

for example in you form.py file, you can do something like this:

class addstaff(forms.ModelForm):
    class Meta:
        model =new_staff
        fields =('first_name', 'last_name', 'gender', 'date_of_birth')


and in your view.py you do something like this:

def newstaff(request):
    if request.POST:
        form =addstaff(request.POST)
        if form.is_valid():
            form.save()
            return render_to_response("successful.html")
    else:
        form =addstaff
    args={}
    args.update(csrf(request))
    args['form']=form
    return render_to_response('addnewstaff.html', args)





Cheers





Teddy McZieuwa

unread,
Dec 7, 2015, 11:30:17 AM12/7/15
to Django users
Thank you very much, I was able to use ModelForm with widgets.......Thanks!
Reply all
Reply to author
Forward
0 new messages