chow
chow

Reputation: 33

Beginner question - the syntax of objects used in Django

i am wondering if the below code is valid as there is no method assigned after objects. However it seem to be working in my code. How is this happened as "create" is only a part of my own defined method (create_user), the computer shouldn't understand my method as it is not a build-in method

def create_user(self, username, email, password):

    new_user = User.objects.create_user(username, email, password)
    new_user.save()

is the string "create" work in some way? or "objects" will create database in the absence of assigned method by default?

Upvotes: 0

Views: 68

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

From the docs:

By default, Django adds a Manager with the name objects to every Django model class.

Upvotes: 1

Related Questions