'Django Oscar now no longer uses get_core_apps in the settings.py. What is the proper solution to customize or extending the existing User model?
I wanted to add more fields such as phone number and email address etc. as part of the registration process for the user. The solution and method found online was outdated, such as using the get_core_apps. I am still learning and new to django-oscar, and are currently working on a project. May I please ask for help or guidance?
models.py
from django.db import models
from oscar.apps.customer.abstract_models import AbstractUser
class Customer(AbstractUser):
phone_number = models.CharField(max_length=10)
date_of_birth = models.DateField()
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'oscar.config.Shop',
'oscar.apps.analytics.apps.AnalyticsConfig',
'oscar.apps.checkout.apps.CheckoutConfig',
'oscar.apps.address.apps.AddressConfig',
'oscar.apps.shipping.apps.ShippingConfig',
'oscar.apps.catalogue.apps.CatalogueConfig',
'oscar.apps.catalogue.reviews.apps.CatalogueReviewsConfig',
'oscar.apps.communication.apps.CommunicationConfig',
'oscar.apps.partner.apps.PartnerConfig',
'oscar.apps.basket.apps.BasketConfig',
'oscar.apps.payment.apps.PaymentConfig',
# 'oscar.apps.offer.apps.OfferConfig',
'oscar.apps.order.apps.OrderConfig',
# 'oscar.apps.customer.apps.CustomerConfig',
'oscar.apps.search.apps.SearchConfig',
'oscar.apps.voucher.apps.VoucherConfig',
'oscar.apps.wishlists.apps.WishlistsConfig',
'oscar.apps.dashboard.apps.DashboardConfig',
'oscar.apps.dashboard.reports.apps.ReportsDashboardConfig',
'oscar.apps.dashboard.users.apps.UsersDashboardConfig',
'oscar.apps.dashboard.orders.apps.OrdersDashboardConfig',
'oscar.apps.dashboard.catalogue.apps.CatalogueDashboardConfig',
'oscar.apps.dashboard.offers.apps.OffersDashboardConfig',
'oscar.apps.dashboard.partners.apps.PartnersDashboardConfig',
'oscar.apps.dashboard.pages.apps.PagesDashboardConfig',
'oscar.apps.dashboard.ranges.apps.RangesDashboardConfig',
'oscar.apps.dashboard.reviews.apps.ReviewsDashboardConfig',
'oscar.apps.dashboard.vouchers.apps.VouchersDashboardConfig',
'oscar.apps.dashboard.communications.apps.CommunicationsDashboardConfig',
'oscar.apps.dashboard.shipping.apps.ShippingDashboardConfig',
# 3rd-party apps that oscar depends on
'widget_tweaks',
'haystack',
'treebeard',
'sorl.thumbnail', # Default thumbnail backend, can be replaced
'django_tables2',
'apps.offer.apps.OfferConfig',
'apps.customer.apps.CustomerConfig',
]
apps.py
from django.apps import AppConfig
import oscar.apps.customer.apps as apps
class CustomerConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'customer'
label = 'customer'
verbose_name = 'Customer'
init.py
default_app_config = "apps.customer.apps.CustomerConfig"
At models.py, I wanted to try adding two new field to the user/customer model according to guide found online.
At settings.py, I added the apps.customer.apps.CustomerConfig and commented out the default one it is using.
At apps.py and init.py, I found some solution online shows that I need to add the code above in to the following files but it did not work either.
However, the method found online uses get_core_apps at the end of INSTALLED_APPS, which I found no longer working. I tried to fork and customize another apps 'view' another way and it worked.
So, I tried using the same method that worked at settings.py but to no avail.
While trying make migrations, error was
Traceback (most recent call last):
File "C:\Users\bryan\oscar_fork_app\manage.py", line 21, in <module>
main()
File "C:\Users\bryan\oscar_fork_app\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\bryan\oscar_fork_app\MY_ENV\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\bryan\oscar_fork_app\MY_ENV\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\bryan\oscar_fork_app\MY_ENV\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\bryan\oscar_fork_app\MY_ENV\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\bryan\oscar_fork_app\MY_ENV\lib\site-packages\django\apps\config.py", line 246, in create
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Cannot import 'customer'. Check that 'apps.customer.apps.CustomerConfig.name' is correct.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
