如何擴展django-oscar客戶模型字段?我已經擴展了登記表包括多個字段,在apps/customer/forms.py
如何擴展django oscar客戶模型字段?
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'))
我也延長了[AbstractUser][1]
的字段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(
但是,創建用戶時,其他字段不會保存到數據庫。有沒有更好的方式來擴展客戶模型以包含我不知道的其他字段?
當我嘗試在外殼調試,我遇到了問題,即該模型是不可呼叫:
>>> from apps.customer.abstract_models import *
>>> mg = UserManager()
>>> mg.create_user('[email protected]', '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
我不知道在django oscar'小號文檔中的說明會的工作,因爲這是用於定製方法,而不是模型上的字段。
任何幫助,將不勝感激。
編輯:
INSTALLED_APPS = INSTALLED_APPS + get_core_apps(
['apps.shipping',
'apps.checkout',
'apps.partner',
'apps.catalogue',
'apps.customer',
])
AUTH_USER_MODEL = 'customer.User'
這是完全可能的字段添加到模型。你的問題是你的應用程序沒有被加載。爲了幫助我們確定問題,請發佈:創建這個新代碼的位置的詳細信息(相對於項目根目錄的文件/目錄),INSTALLED_APPS和AUTH_USER_MODEL設置。 – solarissmoke
我會擴展一個地址模型而不是用戶模型。地址將具有is_default屬性和外鍵給用戶。 –