Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#7505 closed (duplicate)

Abstract class managers have .model pointing to the Abstract rather than the real class

Reported by: tie Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: qsrf-cleanup abstract model manager
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Consider this example:

from django.db import models

class CustomManager(models.Manager):
    def get_query_set(self):
        print "My model is: ", self.model
        return super(CustomManager, self).get_query_set()

class Abstract (models.Model):
    class Meta:
        abstract = True
    objects = CustomManager ()

class Place(Abstract):
    name = models.CharField(max_length=50)
    address = models.CharField(max_length=80)

When this code is evaluated in ./ shell, we get:

>>> models.Place.objects.model
<class 'demoproject.gentest.models.Abstract'>

>>> Place.objects.all()
My model is:  <class 'demoproject.gentest.models.Abstract'>

The normal behavior would be models.Place.objects.model to point to the "real" class - <class 'demoproject.gentest.models.Place'>

Change History (2)

comment:1 Changed 11 years ago by Johannes Dollinger

Keywords: qsrf-cleanup added
milestone: 1.0
Resolution: duplicate
Status: newclosed

closing, the patch for #7154 fixes this.

comment:2 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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