H
H
hardwellZero2015-06-04 16:46:51
Django
hardwellZero, 2015-06-04 16:46:51

How to customize the user model?

Hello Toaster.
Judging by the documentation, you can make custom user registration.
https://docs.djangoproject.com/en/1.8/topics/auth/...
But, is it possible to completely write your own and generally remove the extra tables that django creates in the database? (a habit after Flask)
If not, then how can I store users in my table (own model) and, when registering, put there the specific data I need. I'm not interested in user groups / date and time of the last login and so on.
Z.Y. Developments:
forms.py

class RegistrationForm(forms.ModelForm):
  """
  Form for creating new user
  """
  name = forms.CharField(widget = forms.TextInput(attrs={'placeholder': 'Name'}))
  surname = forms.CharField(widget = forms.TextInput, label = "Surname")
  login = forms.CharField(widget = forms.TextInput, label = "Username")
  email = forms.EmailField(widget = forms.TextInput, label = "E-mail")
  pswd = forms.CharField(widget = forms.PasswordInput, label = "Password")
  pswd_check = forms.CharField(widget = forms.PasswordInput, label = "Repeat password")

views.py
def register(request):
  form = RegistrationForm()
  if request.method == 'POST':
    if form.is_valid():
      RegistrationForm.save()
  return render_to_response('details.html', {'form': form}, RequestContext(request))

urls.py
urlpatterns = [
  url(r'^admin/', include(admin.site.urls)),
  url(r'^register/', register),
]

details.html
<form action ="" method="POST">
  {% csrf_token %}
  Name: {{ form.name }} <br><br>
  Surname: {{ form.surname }} <br><br>
  Login: {{ form.login }} <br><br>
  Pass: {{ form.pswd }} <br><br>
  Check pass: {{ form.pswd_check }} <br><br>
  <button type="submit">Reg</button>
</form>

How now I should save the user in the table in a DB?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2015-06-04
@hardwellZero

But, is it possible to completely write your own and generally remove the extra tables that django creates in the database? (habit after Flask)

Of course you can, from INSTALLED_APPS you throw out this:
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',

And your database will be dry and comfortable :), and then write everything you need yourself.

Y
yesterday69, 2015-06-04
@yesterday69

Maybe this will work:
Python Django (lesson 11) - user registration: https://youtu.be/7SUdbpjQQRI .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question