Opened 11 years ago

Closed 11 years ago

#21297 closed Uncategorized (needsinfo)

CurrentSiteManager returns objects of superclass for sub-models that do not define any additional fields

Reported by: dp@… 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 anonymous, 11 years ago

Summary: CurrentSiteManager returns objects of superclass for models that do not define any additional fieldsCurrentSiteManager returns objects of superclass for sub-models that do not define any additional fields

comment:2 by Tim Graham, 11 years ago

Resolution: needsinfo
Status: newclosed

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 the sub_model table. Please reopen this doesn't work for you.

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