额外的django注册字段

时间:2013-03-06 15:51:20

标签: python django django-registration

我已经关注了如何向django-registration模块添加其他字段的各种教程和解决方案。他们中的一些人做了这个伎俩,但在我同步数据库后,数据没有保存。这是我的文件:

models.py

from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Organization(models.Model):
    #user = models.ForeignKey(User, unique=True)
    name = models.CharField(max_length=100, null=True, unique=True)

forms.py

from registration.forms import RegistrationForm
from django import forms
from drugisok.models import Organization

class OrganizationForm(forms.ModelForm):
    class Meta:
        model = Organization


RegistrationForm.base_fields.update(OrganizationForm.base_fields)

class CustomRegistrationForm(RegistrationForm):
    def save(self, profile_callback=None):
        user = super(CustomRegistrationForm, self).save(profile_callback=None)
        org, c = Organization.objects.get_or_create(user=user, name=self.cleaned_data['name'])

数据库中有一个名为drugisok_organization的表,该表对应于创建的模型。在该表中有一个名为name的列,它也对应于模型。 HTML表单本身为name显示了一个额外的文本输入,但在提交表单时不会保存名称。

0 个答案:

没有答案