Re: Django template iterating through two dictionaries/variables

2016-08-30 Thread Aaron Weisberg
This is why i ask this group. Everyone helped out, but Nate's link pushed me in the right direction. Sometimes I don't even know what to ask stack overflow, but the google group always helps out. Thanks On Tuesday, August 30, 2016 at 11:28:37 AM UTC-5, Nate Granatir wrote: > > You could also

Re: Django template iterating through two dictionaries/variables

2016-08-30 Thread Nate Granatir
You could also just join the dicts before passing them to the template. It looks like it's relatively straightforward (scores is just a list that contains dicts of a 'Number' and a 'score', right?) Then you could turn scores into a dict, assuming Numbers are unique: scores_new = {score['Number'

Re: Django template iterating through two dictionaries/variables

2016-08-29 Thread Asad Jibran Ahmed
Unfortunately without knowing your project layout I can't show you exactly how to load the filters, but you should give this a read: https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/. Your template should look like the example from Ludovic. Asad Jibran Ahmed http://blog.asadjb.c

Re: Django template iterating through two dictionaries/variables

2016-08-29 Thread Aaron Weisberg
I hate to be thick but could you explain to me how to load the filters and also how the template should look with the updated function? Solving this will unlock a ton of functionality for my app. Thanks, Aaron On Aug 29, 2016 12:34 PM, "Asad Jibran Ahmed" wrote: > No problem. The most probabl

Re: Django template iterating through two dictionaries/variables

2016-08-29 Thread Asad Jibran Ahmed
No problem. The most probable reason why you're getting the invalid filter error is because you forgot to load the filters. Your explanation of the workflow is correct, with one small correction. The template will handoff the search for the correct *Score* to the filter function. Whatever the f

Re: Django template iterating through two dictionaries/variables

2016-08-29 Thread Aaron Weisberg
Thanks Asad. Is that why I'm getting errors saying invalid filter name? Also I'm having a difficult time thinking my way through the workflow. I'm defining a new function that requires scores(my URL based dictionary) and person (my database dictionary). The function then asks to return the scores

Re: Django template iterating through two dictionaries/variables

2016-08-29 Thread Asad Jibran Ahmed
Since the example given by Ludovic uses the same variable names that are already present in your context, you won't need to change anything in the context dictionary. Just use {% load APP_NAME %} on top of the template file to load the filter and you should be good to go. On Monday, August 29,

Re: Django template iterating through two dictionaries/variables

2016-08-29 Thread Asad Jibran Ahmed
No need to change the context, since the variable names the example here uses are the same as your existing context. It should work as long as you remember to {% load APPNAME %} your filters in the template first. ​ Asad Jibran Ahmed http://blog.asadjb.com On Mon, Aug 29, 2016 at 6:50 PM, Aaron

Re: Django template iterating through two dictionaries/variables

2016-08-29 Thread Aaron Weisberg
Thanks ludovic, I'm trying to write that python code presently- would I have to also change the context? how would that look? Thanks On Fri, Aug 26, 2016 at 10:40 AM, ludovic coues wrote: > You could write a filter [1]. It would be used like {{ > scores|from_player:person }} and look like tha

Re: Django template iterating through two dictionaries/variables

2016-08-26 Thread ludovic coues
You could write a filter [1]. It would be used like {{ scores|from_player:person }} and look like that: def from_player (scores, player): return scores[player.Number] You might want to adjust to your actual code, check that you got the right arguments and that kind of things. [1] htt

Django template iterating through two dictionaries/variables

2016-08-26 Thread Aaron Weisberg
I didn't really know how to label this question, but I think it's an interesting concept and I haven't seen a resolution anywhere else. I currently have two different dictionaries as context for a template: Enter code here...context ={ 'person':person,