Hi, this is the wrong list for questions about using Django, the right list
for that is https://groups.google.com/forum/#!forum/django-users . This
list is for discussing the development of Django itself.

On 10 July 2017 at 17:15, kanhaiya yadav <[email protected]> wrote:

> Enter code here...
>
> Hi,
>
> I have a model
> class XyzModel (models.Model):
>    name = models.CharField(max_length=NAME_LENGTH)
>    unique_id = models.CharField(max_length=NAME_LENGTH)
>    info = models.CharField(max_length=NAME_LENGTH, blank=True)
>    violation_time = models.DateTimeField()
>
>
>
>
> I have many rows in the database. So I want to group by the results for
> every two hours or for every four hours.
> I want the result something like
>
> name                       violation_date
> interval                                 counts
> abc                           2017-07-01
>  06:00 - 08:00                           20
> xyz                           2017-07-01
> 08:00 - 10:00                           30
>
> My query is
> XyzModel.objects
>             .extra({"day": "date_trunc('hour',violation_time)"}
>             .values("day")
>             .order_by("day")
>             .annotate(count=Count("id"))
> But using this query I can only group the result by one hour interval. I
> want to group by more than one hour interval.
>
> Thanks
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-developers/4df3c2b8-184e-4baf-887d-
> 3d90a5177e2a%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/4df3c2b8-184e-4baf-887d-3d90a5177e2a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM2wKXCO6-mCBz_PNg6Rruxe_v9nNzTZk7CQXP_ridh5PA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to