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

Unable to import AbstractUserCreationForm or AbstractUserChangeForm independently of package #49

Closed
securedirective opened this issue Oct 14, 2017 · 1 comment

Comments

@securedirective
Copy link
Contributor

Specifications

  • Platform/System: macOS 10.12.6
  • Python Version: 3.6.2
  • Django Version: 1.11.6
  • Improved User Version: 1.0a1

Expected Behavior

In a Django project, if I can import the abstract models, I should also be able to import the abstract forms. I can also see instances where extending the UserFactory class could be useful. To provide the greatest flexibility, this project should use Django's get_user_model() function in all locations where it needs to reference the User model.

Actual Behavior

Just as Issue #36 described an inability to import the mix-in model classes without needing to add improved_user to INSTALLED_APPS, the same error occurs when attempting to import AbstractUserCreationForm or AbstractUserChangeForm or attempting to extend the UserCreationForm or UserChangeForm classes.

The moment forms.py is loaded, the following error occurs:

  File "/Users/user/ttt/.venv/lib/python3.6/site-packages/improved_user/forms.py", line 7, in <module>
    from .models import User
  File "/Users/user/ttt/.venv/lib/python3.6/site-packages/improved_user/models.py", line 12, in <module>
    class User(AbstractUser):
  File "/Users/user/ttt/.venv/lib/python3.6/site-packages/django/db/models/base.py", line 118, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class improved_user.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

For the record, the offending line of code also exists in your factories.py, and causes the same error when imported. If UserFactory is intended to be available for import/extending, then the fix will have to be applied to both files.

Context

In my project, I am already importing AbstractBaseUser in order to add more fields. To also provide a custom UserAdmin class to show all my extra user model fields, I included the following in my admin.py:

from improved_user.forms import UserCreationForm, UserChangeForm
from .models import User

class UserAdmin(BaseUserAdmin):
    # The forms to add and change user instances
    add_form = UserCreationForm
    form = UserChangeForm

The import above causes the error.

Steps to Reproduce the Problem

  1. Create a new Django project with a new Django app.
  2. Run pip install git+https://github.com/jambonsw/django-improved-user.git.
  3. Include the sample code above.
  4. Run a Django check to trigger the error.
@jambonrose
Copy link
Owner

I really should have seen this one coming.

I agree that you should be able to import the abstract forms without putting the library in INSTALLED_APPS. I will have a go at fixing this tomorrow.

jambonrose added a commit that referenced this issue Jul 28, 2018
* 📚 Change beta classifier to production/stable
* 📚 Fix comment in extension project
* 📚 Update History
* 📚 Update copyright year
* Bump version: 1.0a2 → 1.0.0
* 🔨 Simplify user extension form use (following #49)
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

2 participants