first, how can set min_length
username
? chachauser._meta.get_field('username').min_length = 2
doesn't work.
second, how can place placeholder
password1
, password2
? forms.passwordinput(attrs={'placeholder' : "6자리 이상"}),
doesn't work.
this customized user
model , usercreationform
.
models.py
from django.core.validators import regexvalidator django.contrib.auth.models import abstractuser django.db import models gender_choices = ( ('m', '남'), ('f', '여'), ) phone_regex = regexvalidator( regex=r'^\d{11}$', message=" '-' 없이 입력해주세요", ) username_regex = regexvalidator( regex=r'^[0-9a-za-z]*$', message='아이디는 영어와 숫자로만 구성되어야 합니다.' ) class chachauser(abstractuser): birth = models.datefield("생년월일") name = models.charfield( "이 름", max_length=4 ) gender = models.charfield( "성 별", max_length=1, choices=gender_choices, default='m' ) phone_number = models.charfield( "핸드폰", validators=[phone_regex], max_length=11 ) job = models.charfield( "직 업", max_length=20, ) # python manage.py createsuperuser 할 때 나오는 항목 required_fields = [ 'birth', 'name', 'gender', 'phone_number', 'job', 'email' ] chachauser._meta.get_field('username').verbose_name = '아이디' chachauser._meta.get_field('username').validators = [username_regex] chachauser._meta.get_field('username').max_length = 20 chachauser._meta.get_field('username').min_length = 2
forms.py
from django import forms django.contrib.auth.forms import usercreationform django.contrib.auth import get_user_model class myusercreationform(usercreationform): birth = forms.datefield( label="생년월일", widget=forms.selectdatewidget( years=range(1970, 2015) ), ) class meta(usercreationform.meta): model = get_user_model() fields = usercreationform.meta.fields + ( 'name', 'gender', 'birth', 'phone_number', 'job', ) exclude = ('email', ) widgets = { 'username' : forms.textinput( attrs={'placeholder': '알파벳, 숫자만 가능(20자 이내)'} ), 'phone_number' : forms.textinput( attrs={'placeholder' : "ex) 01012341234"} ), 'job' : forms.textinput( attrs={'placeholder' : "ex) 한국대 철학과, 선생님 등(20자 이내)"} ), 'password1' : forms.passwordinput( attrs={'placeholder' : "6자리 이상"} ), 'password2' : forms.passwordinput( attrs={'placeholder' : "6자리 이상"} ), }
for first question:
from django.core import validators class chachauser(abstractuser): .................. abstractuser._meta.get_field('username').validators=[validators.minlengthvalidator(2)]
for second question couldn't change password1
in meta.widgets
because not model field. can override widget in __init__
method instead.
Comments
Post a Comment