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
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
On Fri, Feb 23, 2018 at 8:00 AM, Alan <alanwilter@gmail.com> wrote:
Hi Constantine,from my views.py:class status(ListView):
model = Submission
template_name = 'status.html'
def get_queryset(self):
return Submission.objects.filter(juse
r=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.AlanTo view this discussion on the web visit https://groups.google.com/d/--On 23 February 2018 at 03:18, Costja Covtushenko <kostyak7676@gmail.com> wrote: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.On Feb 22, 2018, at 7:34 PM, Alan <alanwilter@gmail.com> wrote:--Hi there,I am using Django 2 with Python 3.5I 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,AlanI'll cycle across Britain in 2018 for a charity, would you considersupporting my cause? http://uk.virginmoneygiving.com/AlanSilva Many thanks!--Alan Wilter SOUSA da SILVA, DScSenior Bioinformatician, UniProtEuropean Bioinformatics Institute (EMBL-EBI)European Molecular Biology LaboratoryWellcome Trust Genome CampusHinxtonCambridge CB10 1SDUnited KingdomTel: +44 (0)1223 494588
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-users@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/CAEznbznNwJW4 .omM%3DMncj8aoBcg3AW8r-yFTMMkb5 ZBiB%3Dsv96Q%40mail.gmail.com
For more options, visit https://groups.google.com/d/optout .
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-users@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/7E9B0630-E1A7 .-4759-B082-998273D6B330%40gmai l.com
For more options, visit https://groups.google.com/d/optout .
--I'll cycle across Britain in 2018 for a charity, would you considersupporting my cause? http://uk.virginmoneygiving.com/ AlanSilva Many thanks!--Alan Wilter SOUSA da SILVA, DScSenior Bioinformatician, UniProtEuropean Bioinformatics Institute (EMBL-EBI)European Molecular Biology LaboratoryWellcome Trust Genome CampusHinxtonCambridge CB10 1SDUnited KingdomTel: +44 (0)1223 494588
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-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .msgid/django-users/ .CAEznbzmC0dA%3DKUpmMf_ DCZh3bKWzi_ sgAYcpZFOWs44EsPLeSw%40mail. gmail.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-users@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/CAHtg44BrMYp%2BH%3D6-W5Or-0q-2SxRp7M08Npne_NYrbyyPCsv7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment