Edit models with key lists

0 views
Skip to first unread message

reza

unread,
Nov 17, 2009, 12:23:20 PM11/17/09
to Google App Engine
I have a model M defined:

class M:
...
categories = db.ListProperty(db.Key)

I'm trying to figure out a way to ensure that when a user chooses to
edit an instance of M they are presented with an edit page that:
1) has a list of checkboxes for each category
2) each category that belongs to the instance of M being edited is
preselected (prechecked)

Since django templates aren't very powerful, I can't do the comparison
of the set of all categories vs the set of categories belonging to M
within the template (and I guess I shouldn't). Can someone point me
to the correct pattern for doing this?

Thanks,
Reza

Joshua Smith

unread,
Nov 17, 2009, 12:58:20 PM11/17/09
to google-a...@googlegroups.com
I usually tackle these kinds of problems with Javascript. In the page you generate, write javascript commands to check the boxes you need.

function setChecks()
{
{% for c in model.categories %}
document.getElementById("{{ c }}").checked = true;
{% endfor %}
}

...
{% for c in categories %}
<input type="checkbox" id="{{ c.key }}">
{% endfor %}
> --
>
> You received this message because you are subscribed to the Google Groups "Google App Engine" group.
> To post to this group, send email to google-a...@googlegroups.com.
> To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-appengine?hl=.
>
>

djidjadji

unread,
Nov 18, 2009, 3:40:18 AM11/18/09
to google-a...@googlegroups.com
Or write a custom filter that checks to see if the current category is
found in the list of checked categories.

2009/11/17 Joshua Smith <Joshua...@charter.net>:

reza

unread,
Nov 18, 2009, 4:25:01 AM11/18/09
to Google App Engine
Thanks for the replies, I like both ideas but I feel like this should
be handled in the controller somehow.

Reza

On Nov 18, 12:40 pm, djidjadji <djidja...@gmail.com> wrote:
> Or write a custom filter that checks to see if the current category is
> found in the list of checked categories.
>
> 2009/11/17 Joshua Smith <JoshuaESm...@charter.net>:
> >> For more options, visit this group athttp://groups.google.com/group/google-appengine?hl=.
Reply all
Reply to author
Forward
0 new messages