Answer the question
In order to leave comments, you need to log in
How to remove table field name override?
Good afternoon.
Extending the User model by adding new fields.
from django.db import models
from django.contrib.auth.models import User
#models.py
class Personal(models.Model):
user = models.OneToOneField(User, on_delete = models.PROTECT)
middle_name = models.CharField(name='middle_name', verbose_name="Отчество", max_length=255)
user_adress = models.CharField(name='user_adress', verbose_name="Адресс", max_length=255)
user_position = models.CharField(name='user_position', verbose_name="Должность", max_length=255)
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import Personal
from django.contrib.auth.models import User
class SaveFields(UserCreationForm):
middle_name = forms.CharField(max_length=255)
user_adress = forms.CharField(max_length=255)
user_position = forms.CharField(max_length=255)
class Meta:
model=User
fields=('middle_name', 'user_adress', 'user_position' )
def index_add(request):
# Регистрация
if request.method == 'POST':
print(request.POST)
form = SaveFields(request.POST)
if request.POST:
if form.is_valid():
form.save()
return render(request, template_name = 'account/signup.html', context={
'title': 'Сотрудники',
'form': form
})
Answer the question
In order to leave comments, you need to log in
From documentation:
These profile models are not special in any way - they are just Django models that happen to have a one-to-one link with a user model. As such, they aren't auto created when a user is created, but a django.db.models.signals.post_save could be used to create or update related models as appropriate.
class AuthUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(u'Электронная почта', unique=True)
date_add = models.DateTimeField(u'Дата добавлен', auto_now_add=True)
is_active = models.BooleanField(u'активен', default=True)
employee = models.OneToOneField('person.Employies', null=True, blank=True, editable=True, verbose_name='Профиль сотрудника', on_delete=models.PROTECT)
is_staff = models.BooleanField(u'администратор', default=False
, help_text=u'определяет возможность входа в панель управления')
roles = models.ManyToManyField(AuthUserRoles, verbose_name=u'Роли')
objects = AuthUserManager()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question