- edited description
Can't subclass the Message model, MessageManager breaks
When subclassing Message and using the MessageManager as the objects manager, queries like inbox
don't work:
class Message(postman.models.Message):
name = CharField(max_length=80, blank=True)
class Meta
manager_inheritance_from_future = True # to use postman's MessageManager
Then in a shell:
> ./manage.py makemigrations
> ./manage.py migrate
> ./manage.py shell
>>> Message.objects.inbox(user=some_user)
psycopg2.ProgrammingError: column core_message.id does not exist
LINE 1: ...L) GROUP BY "postman_message"."thread_id") PM ON ("core_mess...
Note: here core_message is my subclass.
I think this is due to the as_sql
custom query method in query.py.
I'm using Django 1.11.12 with Postman 3.6.1
Comments (9)
-
reporter -
reporter I'm now circumventing the problem by returning
postman.models.Message
instances for the QuerySet withselected_related('message')
to follow through to my message model:class MessageManager(postman.models.MessageManager): def _folder(self, *args, **kwargs): return postman.models.Message.objects._folder(*args, **kwargs).selected_related('message') class Message(postman.models.Message): objects = MessageManager()
A bit unfortunate, since now
inbox
,sent
, etc... return instances ofpostman.models.Message
and I have to do m.message.name to get to my added field. But works for now until we fix the issue. -
reporter - edited description
-
reporter - edited description
-
reporter I just made a pull request for this.
-
repo owner -
assigned issue to
-
assigned issue to
-
repo owner - changed status to open
PR merged, and slightly refined.
Please confirm it works the same on your side. -
reporter It works, thanks for the quick merge.
-
reporter - changed status to resolved
Fixed.
- Log in to comment