pinax-messages
pinax-messages copied to clipboard
Replace first_message and last_message with a more up to date version
Is your feature request related to a problem? Please describe.
I came to realize that the first_message
functionality is limited to an old version of Django. Since django 1.11 we can use a different and more cleaner approach such as earliest
and latest
.
Describe the solution you'd like Replace the first message with
def earliest_message(self):
"""
Returns the earliest (first) message of the thread
"""
try:
return self.messages.earliest('sent_at')
except Message.DoesNotExist:
return
And the same for the last message
def latest_message(self):
"""Returns the latest message of the thread"""
try:
return self.messages.latest('sent_at')
except Message.DoesNotExist:
return
This is useful because we could even pass the default sent_at
and allowing the developer to choose a different field at choice.
Using the first() and last()
methods from the queryset but performance-wise, is slower.