简体   繁体   中英

How to retrieve all data blocks from database at a certain entry in Django?

I am very sorry for this newbie question... I have data stored in the database (mysql) as tuples. These data look like (datetime, frequency, current) ... etc.

How to retrieve all data from database at a certain time? for example, I want to get all the saved data at "2015-9-9 8:23:10"

can you show your model.

You can add created and updated fields to your model and query them to retrieve your data

class Test(models.Model):
    created = models.DateTimeField(
        default=django.utils.timezone.now, blank=True)
    updated = models.DateTimeField(
        default=django.utils.timezone.now, blank=True)

you can query the Test model then using the time you want

Test.objects.all(created=datetime.now())

如果datetime field是创建数据的日期,您可以执行以下操作:

Test.objects.all(datetime__gte=timezone.now)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM