django-oscar-accounts
django-oscar-accounts copied to clipboard
Is it possible to custom views or models like oscar_fork_app in django-oscar?
I was wondering if there is a way that I can custom views or models in django-oscar-accounts? Just like oscar_fork_app command in django-oscar.
It seems like it should work, as https://github.com/django-oscar/django-oscar-accounts/blob/master/src/oscar_accounts/models.py uses if not is_model_registered('oscar_accounts', 'AccountType'):
sequences like django-oscar models.
I tried it on Oscar 2.0.x and Django 2.2, and it fails.
When I modify INSTALLED_APPS
to replace 'oscar_accounts'
with 'custom_oscar_apps.oscar_accounts'
Traceback (most recent call last):
File "manage.py", line 46, in <module>
main()
File "manage.py", line 42, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/cookie/custom_oscar_apps/oscar_accounts/models.py", line 1, in <module>
from oscar_accounts.models import * # noqa isort:skip
File "/usr/local/lib/python3.6/site-packages/oscar_accounts/models.py", line 6, in <module>
class AccountType(abstract_models.AccountType):
File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 95, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class oscar_accounts.models.AccountType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
However if I modify models.py
to define all of the models from oscar_accounts
, I get further.
e.g. custom_oscar_apps/oscar_accounts/models.py
from oscar_accounts import abstract_models
class AccountType(abstract_models.AccountType):
pass
class Account(abstract_models.Account):
pass
class Transfer(abstract_models.Transfer):
pass
class Transaction(abstract_models.Transaction):
pass
class IPAddressRecord(abstract_models.IPAddressRecord):
pass
After that, and forking accounts_dashboard
, it looks like I have a working fork.
@jayvdb I'am looking for some solution for forking oscar_accounts, but nothing work for me, not even your solution. Do you have any update on this or someone else does? Thx
Also looking for a solution here. I see the models are dynamically loaded using oscar's get_model. So it seems like I should be able to override them. No luck yet.