Opened 11 years ago

Closed 11 years ago

#20132 closed Uncategorized (needsinfo)

QuerySets still return the model that was requested is wrong/not clear enough

Reported by: carsten.klein@… Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the documentation on models it reads

[...]
QuerySets still return the model that was requested

There is no way to have Django return, say, a MyPerson object whenever you query for Person objects. A queryset for Person objects will return those types of objects. The whole point of proxy objects is that code relying on the original Person will use those and your own code can use the extensions you included (that no other code is relying on anyway). It is not a way to replace the Person (or any other) model everywhere with something of your own creation.
[...]

I have here a rather complex set up, with a node model class which is not abstract and multiple proxies which represent instances of this node class, for example a document and so on, e.g.

class Node(models.Model):

class Meta:

pass

class Document(node):

class Meta:

proxy = True

Now, querying document.objects.all()[0] will return an instance of Document and not just Node. However, querying Node.objects.all()[0] will of course return an instance of Node and not an instance of Document.

It seems as if the above quoted paragraph needs some work, since the behaviour experienced when using proxies and their inherited managers and their querysets is different based on which manager you are using to query data from the database. Yet, when reading the above paragraph, one might come to the believe that querying would never return the proxy class, regardless of whether you were using the Document proxy model's manager or the manager of the Node model.

Change History (2)

comment:1 by Luke Plant, 11 years ago

I'm not sure which part of the paragraph you think is unclear. The paragraph matches the behaviour you describe IMO.

It sounds to me like you may have misread:

There is no way to have Django return, say, a MyPerson object whenever you query for Person objects

as

There is no way to have Django return, say, a MyPerson object when you do an ORM query.

But I'm just guessing.

comment:2 by Tim Graham, 11 years ago

Resolution: needsinfo
Status: newclosed

Agreed with Luke, I can't figure out what improvement we should make. If you'd like to provide a patch, please re-open.

Note: See TracTickets for help on using tickets.
Back to Top