Opened 7 years ago

Closed 7 years ago

Last modified 4 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: UI/UX:

Description

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 ./manage.py 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 7 years ago by emulbreh

  • Keywords qsrf-cleanup added
  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

closing, the patch for #7154 fixes this.

comment:2 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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