S
S
Sergey Nizhny Novgorod2017-03-23 13:16:45
Django
Sergey Nizhny Novgorod, 2017-03-23 13:16:45

How to make a selection for the "last 30 minutes" in a DateTimeField?

Hello.
Model:

class Chat2Model(models.Model):
    topic = models.CharField(default="Break", choices=TOPIC_CHOICES, max_length=50, help_text="Дерево чата",
                                  verbose_name="Тема Чата")
    author = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
    chatdate = models.DateTimeField(auto_now=True)
    chattext = models.TextField(help_text="Сам чат", verbose_name="Текст чата",
                                         blank=True, null=True)

You need to select all chats whose publication date occurred in the past 30 minutes.
I read the documentation, they suggest doing timestamp.now() and subtracting the last 30 minutes from it. But I'm confused, how is this done in an example? And let's say if there are any short tags for "selection in the last 24 hours"?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question