Я пытаюсь настроить регистрационную форму Django.У меня есть mysite
проект, в котором я создал registration1
приложение.
mysite / registration1 / forms.py
from registration.forms import RegistrationForm
from django import forms
class UserRegistrationForm(RegistrationForm):
unique_id = forms.CharField(min_length=12,max_length=12,label=("Unique id"))
mysite / regbackend.py
import profile
from registration1.forms import UserRegistrationForm
from django.conf import settings
from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site
from registration import signals
from registration.forms import RegistrationForm
from registration.models import RegistrationProfile
class MyBackend(object):
def register(self, request, **kwargs):
username, email, password = kwargs['username'],kwargs['email'], kwargs['password1']
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
new_user = RegistrationProfile.objects.create_inactive_user(username, email,
password, site)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
user = User.objects.get(username=username)
user.unique_id=kwargs['unique_id']
address_user = Address()
address_user.save()
contact_user = Contact(address=address_user,email=user.email)
contact_user.save()
address_company = Address()
address_company.save()
contact_company = Contact(address=address_company)
contact_company.save()
company = Company(contact=contact_company, admin=user)
company.save()
user_profile = UserProfile(user=user,contact=contact_user,position='',company=company )
user_profile.save()
user.save()
return new_user
mysite / urls.py
from registration.views import register
import registration.backends.default.urls as regUrls
import mysite.regbackend
from registration1.forms import UserRegistrationForm
url(r'^accounts/register/$', register,{'backend':'mysite.regbackend.MyBackend','form_class': UserRegistrationForm},name='registration_register'),
Но это дает мне ошибку
'MyBackend' object has no attribute 'registration_allowed'
Я также хочу заменить имя пользователя в оригинальной регистрационной форме Django на unique_id, который вводит пользователь?