Thanks alot Tim, this is all i did: {{for bookings in bookings:}} *<span class="disc {{='blue' if any(bookings.company in q.customer.company for q in quotes) else 'hidden'}}">Quoted</span>* {{pass}} The red line above replaced alot of clearly unnecessary code!
Regards; Mostwanted On Tuesday, January 21, 2020 at 2:26:35 PM UTC+2, Tim Nyborg wrote: > > Simplest fix: use "any" instead: > > {{for bookings in bookings:}} > > {{if any(bookings.company in q.customer.company for q in quotes):}} > <span class="disc {{='blue' if bookings.company in quoted else > 'hidden'}}">Quoted</span> > {{pass}} > > {{pass}} > > > To avoid all this looping, you could have a separate query join the two > tables and count the matches. > > On Saturday, 18 January 2020 23:00:04 UTC, mostwanted wrote: >> >> In my quotation system I have come up with a way to remind users of >> UN-deleted quotations. This helps them from creating new quotations on top >> of old quotations. >> How it works is that when a company has been quoted its name is added to >> a list called the control list and a selected company's name is checked >> against this control list, if it is in the control list it will mean that >> it has been quoted and a blue badge titled quoted will be displayed next to >> the company's name. The problem I am facing now is that if the company has >> several items quoted under it it means that its name will appear several >> times in the control list, this causes the green badge to appear as many >> times as the company name appears in the control list, I want avoid this, >> is there a way to get the badge to appear only once regardless of the >> number of times the company name appears in the control list? >> >> *CONTROLLER* >> def registeredClients(): >> bookings=db(db.Client_Details).select(db.Client_Details.ALL, orderby= >> db.Client_Details.company) >> quotes=db(db.quotation).select() >> return locals() >> >> *CSS* >> .disc >> { >> border: solid 2px transparent; >> border-radius: 50%; >> width: 40px; >> padding: 5px; >> } >> >> .blue >> { >> background-color: blue; >> color: white; >> font-weight: bold; >> font-size: x-small; >> } >> >> *VIEW* >> {{for bookings in bookings:}} >> >> {{for q in quotes:}} >> {{quoted=[q.customer.company]}} >> <span class="disc {{='blue' if bookings.company in quoted else >> 'hidden'}}">Quoted</span> >> {{pass}} >> >> {{pass}} >> >> Please help!!! >> >> Regards; >> >> Mostwanted >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/76ecf62c-d95c-4ede-85d1-5a4638cd3d95%40googlegroups.com.