-1

I have already checked this post but of no use for me.

'module' object is not callable Django

from auth_app.models import UserModel
from django.contrib.auth.hashers import make_password

def UserData(apps, schema):
    UserModel(
        username="username", 
        email_address="[email protected]", 
        is_active=1, 
        password=make_password("12345aA!")
    ).save();

Error Message: TypeError: 'module' object is not callable

3
  • what about using UserModel.create_user(...) instead? Commented Mar 20, 2023 at 0:52
  • 1
    Seems you are using UserModel in a migration. Try to use UserModel = apps.get_model("auth_app", "UserModel") instead Commented Mar 20, 2023 at 5:50
  • 1
    You will need to show us more of the traceback, not just TypeError: 'module' object is not callable. Commented Mar 20, 2023 at 13:18

2 Answers 2

-1

As the comments mention, it would be good to see your full traceback as well as the error, because it's not obvious what part of your code is attempting to call a module.

The two things I can think of based on your code that might be causing your issue are (1) referring to the UserModel directly, and (2) including a semi-colon after .save(). (Python does allow semi-colons, but you should avoid them unless they're needed for the specific purpose of separating statements - I have removed it from your code for now).

Regarding (1), you may be able to avoid the error by using get_user_model as below:

from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import make_password

def UserData(apps, schema):
    UserModel = get_user_model()
    UserModel(
        username="username", 
        email_address="[email protected]", 
        is_active=1, 
        password=make_password("12345aA!")
    ).save()

If this doesn't work, please post your full traceback and more of your code.

Sign up to request clarification or add additional context in comments.

Comments

-3

Instead of directly calling the save() function, you will first have the instantiate the object of the class and then call the save() method. You have to do it as follows,

 from auth_app.models import UserModel
 from django.contrib.auth.hashers import make_password

 def UserData(apps, schema):
        class_obj = UserModel(
            username="username", 
            email_address="[email protected]", 
            is_active=1, 
            password=make_password("12345aA!")
        )
        class_obj.save()

1 Comment

This is not the issue; aside from a single local variable, this code is exactly equivalent to OP's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.