Opened 12 years ago
Closed 12 years ago
#21297 closed Uncategorized (needsinfo)
CurrentSiteManager returns objects of superclass for sub-models that do not define any additional fields
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | contrib.sites | 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
Suppose I have two models, one inheriting the other:
class BaseModel(models.Model):
    title = models.CharField()
    # ...
    objects = models.Manager()
    on_site = CurrentSiteManager()
Then I create a subclass:
class SubModel(BaseModel):
    objects = models.Manager()
    on_site = CurrentSiteManager()
    # ...
Then calling SubModel.on_site.all() returns a QuerySet containing all instances of BaseModel on that site. Checking the SQL reveals that that no table join to the sub_model table occurs.
This can be worked around by instead calling SubModel.objects.filter(site=settings.SITE_ID), but I do believe this to be a bug.
Change History (2)
comment:1 by , 12 years ago
| Summary: | CurrentSiteManager returns objects of superclass for models that do not define any additional fields → CurrentSiteManager returns objects of superclass for sub-models that do not define any additional fields | 
|---|
comment:2 by , 12 years ago
| Resolution: | → needsinfo | 
|---|---|
| Status: | new → closed | 
  Note:
 See   TracTickets
 for help on using tickets.
    
I don't think the use case (subclassing without any additional fields) is advisable without using proxy models -- if there are no fields on
SubModel, then there's no reason to join thesub_modeltable. Please reopen this doesn't work for you.