On 9/8/06, LizzyLiz <[EMAIL PROTECTED]
> wrote:
You won't be able to use 'in' in the templates; the template syntax is _very_ deliberately _NOT_ a programming language.
I can see two options:
1) Pass a list of (user, selected) tuples into your template. Your context will have:
Context({
'accounts': [(a, a in request.user.accounts) for a in accounts]
})
And your template becomes:
<option value="{{ account.0.id }}" {% if account.1 %}selected="True"{% endif %}
>{{account.0.name}}</option>
2) Use the form wrappers. If you get (or create) a manipulator that includes user.accounts, you can put {{ form.accounts }} in your template, Django will roll out the full <select> for you.
In your case, since it is a reverse relationship, the process is a little more complex, but if you look for the 'Editting both sides of self-referential m2m relationship' thread in Django-users, around August 22, I wrote up a fairly detailed walkthrough of the procedure.
Yours,
Russ Magee %-)
I would like to show which of these accounts are already linked to the
user but I'm not sure how to do it - something like:
<option value="{{ account.id }}" {% if account.id in
user.accounts %}selected="True"{% endif %}
>{{ account.name}}</option>
You won't be able to use 'in' in the templates; the template syntax is _very_ deliberately _NOT_ a programming language.
I can see two options:
1) Pass a list of (user, selected) tuples into your template. Your context will have:
Context({
'accounts': [(a, a in request.user.accounts) for a in accounts]
})
And your template becomes:
<option value="{{ account.0.id }}" {% if account.1 %}selected="True"{% endif %}
>{{account.0.name}}</option>
2) Use the form wrappers. If you get (or create) a manipulator that includes user.accounts, you can put {{ form.accounts }} in your template, Django will roll out the full <select> for you.
In your case, since it is a reverse relationship, the process is a little more complex, but if you look for the 'Editting both sides of self-referential m2m relationship' thread in Django-users, around August 22, I wrote up a fairly detailed walkthrough of the procedure.
Yours,
Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---