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 of the corresponding game number. Then the template is looking for the correct value in the scores dictionary that has the same Number identification as the existing person.Number?
I think what is confusing me is the use of "player" in ludovics example
Thanks
Aaron
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 <surfer.a1@gmail.com>On Mon, Aug 29, 2016 at 6:50 PM, Aaron Weisberg <aaron.m.weisberg@gmail.com> wrote: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 <couesl@gmail.com> wrote: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] https://docs.djangoproject.com/en/1.10/howto/custom-template -tags/
> You received this message because you are subscribed to the Google Groups
2016-08-26 15:50 GMT+02:00 Aaron Weisberg <aaron.m.weisberg@gmail.com>:
> 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,
> 'scores':scores,
> }
>
>
> Each of these dictionaries has a common key (person.Number),
> (scores.Number), however the person dictionary is based off of a model in my
> django database, while scores comes from a json feed that I parse through:
>
> I currently run through a table in a template that looks like this:
>
> Enter code here...<table class="table">
> <thead>
> <tr>
> <th>Person</th>
> <th>Person Number</th>
> <th>First Name</th>
> <th>Last Name </th>
> <th> City </th>
> <th> Score</th>
> </tr>
> </thead>
> <tbody>
> {% for person in persons %}
> <tr>
> <td>{{ person.Number }}</td>
> <td>{{ person.firstName }}</td>
> <td>{{
> person.lastName }}</td>
> <td>{{
> person.city }}</td>
>
> <td>??'''scores.score1 goes here'''</td>
>
> {% endfor %}
>
> </table>
>
> What I'm trying to figure out to do is figure out how to get that final
> detail loaded into the table where we would find the score specific to that
> person.Number. In other words how to go through my scores dictionary in
> this template and find the corresponding score1 using the person.Number from
> the other dictionary as the value.
>
>
> Let me know if you have any ideas.
>
> Thanks.
>
>
> --
> "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/d05c8fc4-706b .-422b-bc11-b656f1950dea%40goog legroups.com
> For more options, visit https://groups.google.com/d/optout .
--
Cordialement, Coues Ludovic
+336 148 743 42
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/UlgghbsoqYI/u .nsubscribe
To unsubscribe from this group and all its topics, 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/CAEuG%2BTatGS .wstRkfEDpZdeB6yMv2BobiaQ_Zb3CE L7ZXr5kE-g%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/CAL5RJ55RzR6M .uwXS-ARFKKDb948ijOW9jfp27Th76X t006%3D_5g%40mail.gmail.com
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/ .UlgghbsoqYI/unsubscribe
To unsubscribe from this group and all its topics, 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/CA% .2BYYaWequ_C-hAGkMWWjg1R8MWxXk% 3DLwitdP1M92hGGy0B%2BYrg% 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/CAL5RJ57dxr2PNp%2Bfs%3DcsqzH7Y94c%2BfyoGnSFpai_K%2BGHCBuu8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment