ixc / wagtail-instance-selector

A widget for Wagtail's admin that allows you to create and select related items
MIT License
54 stars 17 forks source link

Incompatible with Custom User Model #12

Closed infinityplusone closed 3 years ago

infinityplusone commented 3 years ago

I've been working with a custom user model in my latest project and when I tried to pull in the InstanceSelectorPanel into one of my models.py files, I got this error:

  File ".../venv/lib/python3.8/site-packages/instance_selector/registry.py", line 15, in <module>
    User = get_user_model()
  File ".../venv/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 161, in get_user_model
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'accounts.User' that has not been installed

I'm fairly certain this is because I am defined AUTH_USER_MODEL in my base.py as 'accounts.User'.

For context, I followed the instructions here when moving to my custom user model.

According to this, the problem is most likely in registry.py:

Note that get_user_model() cannot be called at the module level in any models.py file (and by extension any file that a models.py imports), since you'll end up with a circular import. Generally, it's easier to keep calls to get_user_model() inside a method whenever possible (so it's called at run time rather than load time), and use settings.AUTH_USER_MODEL in all other cases.

I'll submit a PR shortly with what I believe is the proper fix.