Allauth不会保存其他字段(Allauth will not save additional fields)
我一直试图扩展我的allauth注册表单,但似乎无法使它工作,我没有收到任何错误消息,一切似乎工作正常,除了我的所有其他字段都没有得到保存。 如果你能看到我做错了,请告诉我,谢谢!
楷模 -
from django.db import models from django.contrib.auth.models import User class EmployerProfile(models.Model): region_choice = ( ('1', 'Auckland'), ('2', 'Wellington'), ('3', 'Christchurch') ) suburb_choice = ( ('1', 'Glendowie'), ('2', 'Kohimarama'), ('3', 'Mission Bay') ) industry_choice = ( ('1', 'Restaurant'), ('2', 'IT'), ('3', 'Construction') ) user = models.OneToOneField(User, unique=True) home_number = models.IntegerField(max_length=12) mobile_number = models.IntegerField(max_length=12) business_name = models.CharField(max_length=50) business_address_number = models.IntegerField() business_address_street = models.CharField(max_length=50) business_address_region = models.CharField(max_length=50, choices=region_choice) business_address_suburb = models.CharField(max_length=50, choices=suburb_choice) business_address_postcode = models.IntegerField(max_length=4) business_industry = models.CharField(max_length=50, choices=industry_choice) class Meta: verbose_name = 'Employer Profile'
形式 -
from django import forms from models import EmployerProfile class SignupForm(forms.Form): first_name = forms.CharField(max_length=30, label='First Name') last_name = forms.CharField(max_length=30, label='Last Name') home_number = forms.IntegerField(label='Home Number') mobile_number = forms.IntegerField(label='Mobile Number') business_name = forms.CharField(label='Business Name') business_address_number = forms.IntegerField(label='Street Number') business_address_street = forms.CharField(label='Street Name') business_address_region = forms.ChoiceField(choices=EmployerProfile.region_choice, label='Region') business_address_suburb = forms.ChoiceField(choices=EmployerProfile.suburb_choice, label='Suburb') business_address_postcode = forms.IntegerField(label='Postcode') business_industry = forms.ChoiceField(choices=EmployerProfile.industry_choice, label='Industry') def signup(self, request, user): user.first_name = self.cleaned_data['first_name'] user.last_name = self.cleaned_data['last_name'] user.home_number = self.cleaned_data['home_number'] user.mobile_number = self.cleaned_data['mobile_number'] user.business_name = self.cleaned_data['business_name'] user.business_address_number = self.cleaned_data['business_address_number'] user.business_address_street = self.cleaned_data['business_address_street'] user.business_address_region = self.cleaned_data['business_address_region'] user.business_address_suburb = self.cleaned_data['business_address_suburb'] user.business_address_postcode = self.cleaned_data['business_address_postcode'] user.business_industry = self.cleaned_data['business_industry'] user.save() class Meta: model = EmployerProfile
设置 -
SITE_ID = 1 ACCOUNT_SIGNUP_FORM_CLASS = 'profiles.forms.SignupForm' ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_VERIFICATION = None LOGIN_REDIRECT_URL = '/'
I have been trying to extend my allauth signup form but cannot seem to get it working, I receive no error messages and everything appears to work fine except all my additional fields do not get saved. Please tell me if you can see what I am doing wrong, thanks!
Models -
from django.db import models from django.contrib.auth.models import User class EmployerProfile(models.Model): region_choice = ( ('1', 'Auckland'), ('2', 'Wellington'), ('3', 'Christchurch') ) suburb_choice = ( ('1', 'Glendowie'), ('2', 'Kohimarama'), ('3', 'Mission Bay') ) industry_choice = ( ('1', 'Restaurant'), ('2', 'IT'), ('3', 'Construction') ) user = models.OneToOneField(User, unique=True) home_number = models.IntegerField(max_length=12) mobile_number = models.IntegerField(max_length=12) business_name = models.CharField(max_length=50) business_address_number = models.IntegerField() business_address_street = models.CharField(max_length=50) business_address_region = models.CharField(max_length=50, choices=region_choice) business_address_suburb = models.CharField(max_length=50, choices=suburb_choice) business_address_postcode = models.IntegerField(max_length=4) business_industry = models.CharField(max_length=50, choices=industry_choice) class Meta: verbose_name = 'Employer Profile'
Forms -
from django import forms from models import EmployerProfile class SignupForm(forms.Form): first_name = forms.CharField(max_length=30, label='First Name') last_name = forms.CharField(max_length=30, label='Last Name') home_number = forms.IntegerField(label='Home Number') mobile_number = forms.IntegerField(label='Mobile Number') business_name = forms.CharField(label='Business Name') business_address_number = forms.IntegerField(label='Street Number') business_address_street = forms.CharField(label='Street Name') business_address_region = forms.ChoiceField(choices=EmployerProfile.region_choice, label='Region') business_address_suburb = forms.ChoiceField(choices=EmployerProfile.suburb_choice, label='Suburb') business_address_postcode = forms.IntegerField(label='Postcode') business_industry = forms.ChoiceField(choices=EmployerProfile.industry_choice, label='Industry') def signup(self, request, user): user.first_name = self.cleaned_data['first_name'] user.last_name = self.cleaned_data['last_name'] user.home_number = self.cleaned_data['home_number'] user.mobile_number = self.cleaned_data['mobile_number'] user.business_name = self.cleaned_data['business_name'] user.business_address_number = self.cleaned_data['business_address_number'] user.business_address_street = self.cleaned_data['business_address_street'] user.business_address_region = self.cleaned_data['business_address_region'] user.business_address_suburb = self.cleaned_data['business_address_suburb'] user.business_address_postcode = self.cleaned_data['business_address_postcode'] user.business_industry = self.cleaned_data['business_industry'] user.save() class Meta: model = EmployerProfile
Settings -
SITE_ID = 1 ACCOUNT_SIGNUP_FORM_CLASS = 'profiles.forms.SignupForm' ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_EMAIL_VERIFICATION = None LOGIN_REDIRECT_URL = '/'
原文:https://stackoverflow.com/questions/31366278
更新时间:2024-05-04 19:05
最满意答案
这里有一些文档可以帮助您入门(应该帮助您解决正确的问题):
Here's a few docs to get you started (should help you google the right questions):
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在哪里可以找到一个CSV到NSArray解析器的Objective-C?(Where can I find a CSV to NSArray parser for Objective-C? [closed])[2022-06-10]
我终于找到清理我在代码文件夹中的解析器,并将其发布在Github上: http : //github.com/davedelong/CHCSVParser 这是相当彻底的 它处理各种转义方案,字段中的换行符,注释等。它还使用智能文件加载,这意味着您可以在受限内存条件下安全地解析大量文件。 I finally got around to cleaning up a parser I've had in my code folder and posted it on Github: http://github. ... -
您可以参考“我如何使用Objective-C创建zip文件?”接受的答案。 , 要么 Objective-C是C的超集,所以你可以自由地链接到任何C zip库对你来说很方便(比如zlib ),或者 您可以调出Linux系统上可用的zip和unzip shell实用程序,并使用管道或文件的临时位置与它们进行交互。 You could reference the accepted answer to "How can I create a zip file by using Objective-C?", or ...
-
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html
-
不,它没有。 资源 No, it doesn't. Source
-
在objective-c中获取多页pdf文档中单页的大小(Get size of single pages in a multi-page pdf document in objective-c)[2022-02-04]
iOS / OS X PDF相关API中没有此类信息。 由于PDF文件的结构计算PDF页面在磁盘上占用的大小非常复杂。 此外,由于页面可以共享资源,因此单独页面大小的总和将不等于最终文件的大小。 There is no such information in iOS/OS X PDF related APIs. Due to the structure of PDF files computing the size a PDF page occupies on disk is quite complicat ... -
我在哪里可以找到解释Objective-C如何实现的文档(Where can i find a document explaining how Objective-C is implemented)[2023-03-31]
这里有一些文档可以帮助您入门(应该帮助您解决正确的问题): http://www.mulle-kybernetik.com/artikel/Optimization/opti-9.html http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html Here's a few docs to get you started (should help you google the right questio ... -
你的问题不是愚蠢的 - 但它是非常广泛的,很难回答。 你在谈论输出HTML吗? 或者你在谈论服务器端编程? Objective-C使用Cocoa,还是只使用vanilla Objective-C? 首先,使用cocoa框架的任何东西都无法为Web编译。 期。 你可以模仿Cocoa框架(就像Cappuccino那样),但这不是一个小任务。 可以使用Objective-c(服务器端)进行Web开发,但目前还不是真的可行,因为您必须从头开始编写库,并且还有很多其他选项可用于完成Web开发框架(Ruby,PHP,P ...
-
我在这个页面上找到了详细的Objective-C 2.0语法: https : //github.com/iamdc/Objective-C-Grammar/blob/master/ObjC.Grm I found a detailed Objective-C 2.0 grammar on this page: https://github.com/iamdc/Objective-C-Grammar/blob/master/ObjC.Grm