You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
defearliest_message(self):
""" Returns the earliest (first) message of the thread """try:
returnself.messages.earliest('sent_at')
exceptMessage.DoesNotExist:
return
And the same for the last message
deflatest_message(self):
"""Returns the latest message of the thread"""try:
returnself.messages.latest('sent_at')
exceptMessage.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.
The text was updated successfully, but these errors were encountered:
tarsil
changed the title
Replace first_message and last_message content
Replace first_message and last_message with a more up to date version
Apr 29, 2020
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 asearliest
andlatest
.Describe the solution you'd like
Replace the first message with
And the same for the last message
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.The text was updated successfully, but these errors were encountered: