Creating an application form

23 views
Skip to first unread message

Aida

unread,
Jul 10, 2016, 12:40:27 PM7/10/16
to Django users
Hello,

I want to create a form to apply in,  this form will contain fields for name, surname, e-mail, text area and  also i want it to contain checkbox-es. Data that will be inserted in those areas to be saved in db. How can i come up with this?

ludovic coues

unread,
Jul 10, 2016, 3:07:28 PM7/10/16
to django...@googlegroups.com
First, you need a model to store the data in the database.
Then, you can use a CreateView as explained at [1].

You should have something like that at the end.
models.py:
from django.db import models

class User(models.Model):
name = models.CharField(max_length=128)
newsletter = models.BooleanField()

views.py:
from django.views.generic.edit import CreateView
from .models import User

class UserCreate(CreateView):
model = User
fields = ['name', 'newsletter']

urls.py:
from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^user/create/$', views.UserCreate.as_view(), name="user_create"),
]

If you have more question, like how all that fit together, I suggest
strongly to do at least one django tutorial. There are several of high
quality. If the official one is too rough for you, django girls [2]
offer an alternative for beginner.

[1] https://docs.djangoproject.com/en/1.9/topics/class-based-views/generic-editing/#model-forms

[2] http://tutorial.djangogirls.org/
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/36850358-c3f6-4acf-b50b-25a4602baca2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages