Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to custom views or models like oscar_fork_app in django-oscar? #57

Open
joyzhang15 opened this issue Mar 6, 2018 · 3 comments

Comments

@joyzhang15
Copy link

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.

@jayvdb
Copy link

jayvdb commented Apr 13, 2020

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.

@filip-spaldon
Copy link

filip-spaldon commented Jun 16, 2020

@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

@1john
Copy link

1john commented Jan 22, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants