오케이 다시 묻습니다.장고 등록 및 데이터 저장
이번엔 백엔드에서 장고 등록을 사용하고 있습니다.
내 regbackend.py가 다른 많은 기능을 갖고있는 이유에 대해 궁금한 사람이 있으면 서버가 해당 메소드에 대해 불만을 제기하고 있으므로 방금 복사하여 붙여 넣었습니다.
그러나 백엔드가 데이터베이스에 저장할 저장 함수를 어떻게 호출하는지 알고 싶습니다.
저장 방법은 여기에 포함되어 있기 때문에 여기에 포함 시켰습니다. 그렇지 않으면 이미 내 forms.py에 있습니다.
제발 도와주세요, 사실 pinax 및 django 프로필을 보았습니다.하지만 내 프로젝트를 완전히 개편해야합니다.
정말 고마워요.
forms.py :
from django import forms
from r2.models import Keyword
from r2.models import UserProfile
from registration.forms import RegistrationForm
from registration.models import RegistrationProfile
from django.utils.translation import ugettext_lazy as _
from registration.forms import RegistrationForm, attrs_dict
class ProjectSpecificRegistrationForm(RegistrationForm):
keywords = forms.ModelChoiceField(queryset=Keyword.objects.all())
first_name =forms.CharField(widget=forms.TextInput(attrs=attrs_dict),label=_(u'First Name'))
last_name =forms.CharField(widget=forms.TextInput(attrs=attrs_dict),label=_(u'Last Name'))
def save(self, profile_callback=None):
new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
password=self.cleaned_data['password1'],
email=self.cleaned_data['email'])
new_profile = UserProfile(user=new_user,username=self.cleaned_data['username'], keywords_subscribed=self.cleaned_data['keywords'],first_name=self.cleaned_data['first_name'],last_name=self.cleaned_data['last_name'])
new_profile.save()
return new_user()
Urls.py는 :
from django.conf import settings
from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from registration import signals
from registration.forms import RegistrationForm
from registration.models import RegistrationProfile
from r2.forms import ProjectSpecificRegistrationForm
from r2.models import *
class RegBackend(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)
user = User.objects.get(username=new_user.username)
user.first_name = kwargs['first_name']
user.last_name = kwargs['last_name']
user.keywords = kwargs['keywords']
signals.user_registered.send(sender=self.__class__, user=new_user, request=request)
user.save()
return new_user
def save(self, profile_callback=None):
print('Came in')
new_user = RegistrationProfile.objects.create_inactive_user(username=self.cleaned_data['username'],
password=self.cleaned_data['password1'],
email=self.cleaned_data['email'])
new_profile = UserProfile(user=new_user,username=self.cleaned_data['username'], keywords_subscribed=self.cleaned_data['keywords'],first_name=self.cleaned_data['first_name'],last_name=self.cleaned_data['last_name'])
new_profile.save()
return new_user()
def registration_allowed(self, request):
return getattr(settings, 'REGISTRATION_OPEN', True)
def post_registration_redirect(self, request, user):
return ('registration_complete',(), {})
의도가 잘못되었습니다. – DrTyrsa