Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace first_message and last_message with a more up to date version #53

Open
tarsil opened this issue Apr 29, 2020 · 0 comments
Open

Comments

@tarsil
Copy link

tarsil commented 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 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.

@tarsil 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant