How do I extend the django-oscar customer models fields? I have extended the registration form to include more fields, in apps/customer/forms.py
class EmailUserCreationForm(forms.ModelForm):
email = forms.EmailField(label=_('Email address'))
password1 = forms.CharField(
label=_('Password'), widget=forms.PasswordInput,
validators=password_validators)
password2 = forms.CharField(
label=_('Confirm password'), widget=forms.PasswordInput)
#### The extra fields I want to add #####
first_name = forms.CharField(label=_('First name'))
last_name = forms.CharField(label=_('Last name'))
business_name = forms.CharField(label=_('Business name'))
business_address = forms.CharField(label=_('Business address'))
city = forms.CharField(label=_('City'))
I have also extended the [AbstractUser][1]
's fields in apps/customer/abstract_models.py
.
class AbstractUser(auth_models.AbstractBaseUser,
auth_models.PermissionsMixin):
"""
An abstract base user suitable for use in Oscar projects.
This is basically a copy of the core AbstractUser model but without a
username field
"""
email = models.EmailField(_('email address'), unique=True)
first_name = models.CharField(
_('First name'), max_length=255, blank=True)
last_name = models.CharField(
_('Last name'), max_length=255, blank=True)
is_staff = models.BooleanField(
_('Staff status'), default=False,
help_text=_('Designates whether the user can log into this admin '
'site.'))
is_active = models.BooleanField(
_('Active'), default=True,
help_text=_('Designates whether this user should be treated as '
'active. Unselect this instead of deleting accounts.'))
date_joined = models.DateTimeField(_('date joined'),
default=timezone.now)
#######################################
# Additional user fields I have added #
#######################################
business_name = models.CharField(
_('Business name'), max_length=255, blank=True)
business_address = models.CharField(
_('Business address'), max_length=255, blank=True)
city = models.CharField(
However, when a user is created, the additional fields are not getting saved to the database. Is there a better way of extending the customer model to include additional fields I'm not aware of?
When I try to debug in the shell, I run into the issue where the model is not callable:
>>> from apps.customer.abstract_models import *
>>> mg = UserManager()
>>> mg.create_user('testemail@test.com', 'testpassword', buisness_name='test_business')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<my_working_dir>/apps/customer/abstract_models.py", line 34, in create_user
last_login=now, date_joined=now, **extra_fields)
TypeError: 'NoneType' object is not callable
I'm not sure the instructions given in django oscar's docs will work, as that is for customizing methods, not fields on the model.
Any help would be appreciated.
Edit:
INSTALLED_APPS = INSTALLED_APPS + get_core_apps(
['apps.shipping',
'apps.checkout',
'apps.partner',
'apps.catalogue',
'apps.customer',
])
AUTH_USER_MODEL = 'customer.User'