You can use islice from itertools in this way
islice('ABCDEFG', 0, None, 2) --> A C E G
In your case you would replace
chart = temp_db.objects.filter(date__gte=beg_range)
with
chart = [x for x in islice(temp_db.objects.filter(date__gte=beg_range), 0,
None, 2)]
That will give you every other instance from your query set starting with the
first
On Friday, January 25, 2019 at 9:02:33 AM UTC-5, Stéphane Manguette wrote:
>
> Hello;
>
> I've a DBB with a lot of values which are recorded every 2 minutes (this
> cannot be changed).
>
> I'm trying to get all values recorded over the last 24h
>
> def dashboard(request):
> version = version_global
> end_range = datetime.now()
> beg_range = end_range - timedelta(days=1)
> chart = temp_db.objects.filter(date__gte=beg_range)
> last_entry = chart.latest('date')
> return render(request, 'index.html', locals())
>
> The following code works perfectly. The goal is to populate a Chart.js in
> index.html. Unfortunately, there is a lot to transmit making it long to
> charge. Since my chart is not mainly meant to show trends; I could skip one
> data over two. Is there a function do do so?
>
> Thanks a lot,
>
> Stéphane
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" 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-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b62c45f4-7143-4e60-b9eb-7cf65902a25d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.