object_list in html

44 views
Skip to first unread message

Alan

unread,
Feb 22, 2018, 7:36:55 PM2/22/18
to django...@googlegroups.com
Hi there,

I am using Django 2 with Python 3.5

I have this query, simple, in mysql:

select * from submit_submission where jstatus = 'Running' and juser = 'jonhdoe';

Basically, I have a table that tracks the jobs I am running.

In my html, I'd like to replace this part (in red):

{% if object_list.last.jstatus == 'Running' %}

<meta http-equiv="refresh" content="5"> <center><h0>Page automatically refreshed every 5 seconds | {% now "jS M y H:i" %}</h0></center>

{% else %}<center><h0>No running jobs.</h0></center>

{% endif %}


​with something equivalent to my query above where I need to know if there's at least one job running for a given user.

I've been looking at https://docs.djangoproject.com/en/2.0/ref/models/querysets ​but I couldn't work out a solution.

​Many thanks in advance,

Alan​

--
I'll cycle across Britain in 2018 for a charity, would you consider
Many thanks!
--
Alan Wilter SOUSA da SILVA, DSc
Senior Bioinformatician, UniProt
European Bioinformatics Institute (EMBL-EBI)
European Molecular Biology Laboratory
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
United Kingdom

Costja Covtushenko

unread,
Feb 22, 2018, 10:19:47 PM2/22/18
to django...@googlegroups.com
Hi Alan,

How did you receive that `object_list`?
You should filter it based on you user and ‘Running’ inside the view. And then just check if it has count > 0.

I hope that does have sense to you.

Regards,
Constantine C.

--
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 django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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/CAEznbznNwJW4omM%3DMncj8aoBcg3AW8r-yFTMMkb5ZBiB%3Dsv96Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Alan

unread,
Feb 23, 2018, 11:02:10 AM2/23/18
to django...@googlegroups.com
Hi Constantine,

from my views.py:

class status(ListView):

    model = Submission

    template_name = 'status.html'


    def get_queryset(self):

        return Submission.objects.filter(juser=self.request.user).exclude(jstatus='Deleted')


If I could create a parameter say runFlag (True of False) where it would be true for:

select * from submit_submission where jstatus = 'Running' and juser = 'jonhdoe';

Would django equivalente be:
Submission.objects.filter(juser=self.request.user, jstatus=‘Running)

If so, then how to tweak this class so I could have 'runFlag' in the template html?

Sorry for those questions, I used to use Django 10 years ago and had solutions for that, now I am trying to learn Django 2.0.

Alan


To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
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 django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

Dylan Reinhold

unread,
Feb 23, 2018, 12:39:29 PM2/23/18
to django...@googlegroups.com
I would add an is_running flag into the context_data

    def get_context_data(self, **kwargs):
        data = super().get_context_data(**kwargs)
        data['is_running'] = Submission.objects.filter(juser=self.request.user jstatus='Running').exists()
        return data

  Then in your template {% if is_running %}xxxxx{% endif %}

Dylan

Alan

unread,
Feb 26, 2018, 6:52:06 AM2/26/18
to django...@googlegroups.com
That worked! Many thanks!


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages