Z
Z
zelsky2015-11-06 09:44:48
Django
zelsky, 2015-11-06 09:44:48

Before checking the user for registration?

You need to dab in the function in the admin panel for a user with the rights to add users. Automatic user registration and adding is_staff only for authorization through the admin panel without any rights. I thought to create a button, but I don’t know how to expand it. Please advise.

# coding: utf-8
from django.db import models

# Create your models here.
class RegisterUser(models.Model):
    """
    Сюди відправляються данні від бажаючих зареєструватись
    """
    first_name = models.CharField(max_length=255,verbose_name="Ім’я")
    second_name = models.CharField(max_length=255,verbose_name="Прізвище")
    zvannya = models.CharField(max_length=255,verbose_name="Звання")
    login_name  = models.CharField(blank=True,max_length=255,verbose_name="Ім’я після додавання")
    referal = models.CharField(max_length=255,verbose_name="Прізвище та ім’я хто запросив")
    email = models.EmailField(max_length=255,verbose_name="Поштова скринька")
    phone_number = models.CharField(max_length=255,verbose_name="Номер мобільного")
    notes = models.CharField(max_length=255,verbose_name="Примітки")
    checked = models.BooleanField(default=False)
    pass_word = models.CharField(default=None,max_length=100,verbose_name='Пароль')

    def __unicode__(self):
        return '%s %s %s %s' % (self.first_name, self.second_name,self.login_name,self.checked)
    class Meta:
        verbose_name = u"Заявку"
        verbose_name_plural = u"Заявки"

def registeruser(request):
    """
    Підтвердження для реєстрації
    """
    context = {}
    if request.method == 'POST':
        first_name = request.POST['first_name']
        second_name = request.POST['second_name']
        zvannya = request.POST['zvannya']
        referal = request.POST['referal']
        email = request.POST['email']
        phone_number = request.POST['phone_number']
        notes = request.POST['notes']
        pass_word = request.POST['pass_word']
        if first_name and second_name and zvannya and referal and email and phone_number and notes and pass_word:
            new_user = RegisterUser(first_name=first_name,second_name=second_name,zvannya=zvannya,
                                    referal=referal,email=email,phone_number=phone_number,notes=notes
                                    ,pass_word=pass_word)
            new_user.save()
            return render(request,'index.html',context)

    else:
        pass

    return render(request,'register.html',context)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question