-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="user@gmail.com", 
        is_active=1, 
        password=make_password("12345aA!")
    ).save();

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

Pankaj
  • 9,749
  • 32
  • 139
  • 283

2 Answers2

-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="user@gmail.com", 
        is_active=1, 
        password=make_password("12345aA!")
    ).save()

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

Pankaj
  • 9,749
  • 32
  • 139
  • 283
-4

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="user@gmail.com", 
            is_active=1, 
            password=make_password("12345aA!")
        )
        class_obj.save()
Pankaj
  • 9,749
  • 32
  • 139
  • 283
SimbaOG
  • 460
  • 2
  • 8
  • 3
    This is not the issue; aside from a single local variable, this code is exactly equivalent to OP's. – AKX Mar 20 '23 at 13:17