0

i need to group data based on hour extracted from a 13 digit unix timestamp.those timestamps are stored in a model(Hello) field called startTime with IntegerField

timehour = Hello.objects.values(
    #hour=ExtractHour('startTime')
    hour=datetime.datetime.fromtimestamp((Hello.startTime)).strftime('%H')
).annotate(
    times=Count('pk')
).order_by('hour')

my model looks like this

class Hello(models.Model):
   startTime=models.IntegerField(blank=True)
Vivek Anand
  • 381
  • 1
  • 10
  • 1
    You're doing something completely wrong. `values` method used to get only certain fields, but not for annotation. The error is caused by the fact that you're trying to get field value from model in improper way - `Hello.startTime` – Charnel Jul 07 '20 at 16:10
  • can u suggest another way of doing the thing i am doing as mention in first two lines – Vivek Anand Jul 07 '20 at 16:14
  • Please show your models first. – Charnel Jul 07 '20 at 16:33
  • class Hello(models.Model): startTime = models.IntegerField( blank=True, null=True) – Vivek Anand Jul 07 '20 at 16:38
  • `InteractionWith` as well. Also, you can update your question instead of posting models code in comments. – Charnel Jul 07 '20 at 16:40

0 Answers0