0

i want to get Device created today this is my model :

class Device(models.Model):
    hostname = models.CharField(max_length=200, null=True)
    password = models.CharField(max_length=200, null=True)
    type = models.CharField(max_length=200,choices=dtype, null=True)
    ipadress = models.CharField(max_length=200, null=True)
    date_created = models.DateTimeField(auto_now_add=True, null=True)

and i tried this views but didn't work :

device_today = Device.objects.filter(date_created=today).count()

any advice ?

  • Take a look at [this question](https://stackoverflow.com/questions/11245483/django-filter-events-occurring-today) – MattRowbum Jun 14 '21 at 02:35

1 Answers1

1

You can try this.

import datetime
today=datetime.date.today()
Device.objects.filter(date_created__date=today)
arjun
  • 7,230
  • 4
  • 12
  • 29