Mahesh
Mahesh

Reputation: 266

Difference between model classes and model instances in Django (documentation)

I was reading Django Documentation and I got across this line.

     Managers are only accessible via model classes, not the model 
     instances.

What is the meaning of this line? I am not able to comprehend this. I know what are Model classes ( Represents the Table in Database if I am not wrong). Are the model instances same as what we call "objects" sometimes?

What does this line mean actually? IS this some OOP concept or just Django?

Upvotes: 1

Views: 1221

Answers (1)

ruddra
ruddra

Reputation: 51958

Lets say you have a model X:

class X(models.Model):
    pass

Now if you want to access the Manager method, you need to access like this:

X.objects.all()

But the following line will not work:

> x = X()  # model instance
> x.save()
> x.objects  << will throw error

FYI: its django specific, not OOP.

Upvotes: 3

Related Questions