关于如何向django-registration
模块添加其他字段,我已经学习了各种教程和解决方案。他们中的一些人做到了这一点,但在我同步数据库之后,数据并没有被保存。这是我的档案:
型号.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)
表单.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
显示一个额外的文本输入,但提交表单时不会保存名称。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐