I want to override an existing model and use a different manager, while keeping the same db table so I can query the same data using different managers in different places.
My code as following:
MyTagging/models.py
from tagging.models import Tag as tagging_tag, TagManager as tagging_tagmanager
class TagManager(tagging_tagmanager):
def get_query_set(self):
return super(TagManager,self).get_query_set().filter(site=settings.SITE_ID)
class Tag(tagging_tag):
#id = models.AutoField(primary_key=True)
objects=TagManager()
class Meta:
db_table="tagging_tag"
But if I sql it the code is going to be like this:
CREATE TABLE "Tagging_local_tag" (
"tag_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "tagging_tag" ("id")
)
;
The tag_ptr_id field is causing problems here, it’s trying to create a new table and reference the original one.
Is there any way of dealing with this?
Just create a proxy model like this: