I have followed various tutorials and solutions on how to add additional fields to django-registration
module. Some of them did the trick, but after I synced the database, data is not saved. Here are my files:
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'])
There is a table in the database with name drugisok_organization
which corresponds to the model created. In that table there is a column named name
which also corresponds to the model. HTML form itself shows one additional text input for name
, but name is not saved when the form is submitted.