On Tue, Jun 16, 2009 at 4:43 PM, MiratCanBayrak<miratcanbay...@gmail.com> wrote:
>
> Hi i wrote an application called category. As you guess it an
> application to hold categories. Than i wanted to use it on my site. I
> wrote a function that builds html code for displaying categories, but
> now i want to use that view as widget.
>
> How can i do it? how can i build a widget ?
>
> That is function building that produces html code : http://dpaste.com/56008/,
> its output is http://g.imagehost.org/view/0216 , produced html code is
> http://dpaste.com/56011/ and my category model is here : 
> http://dpaste.com/56009/

As in a django.forms widget?

You'd extend one of the existing widgets (Select or SelectMultiple - I
can't see which would be needed in your case, as the link to the
output screenshot doesn't work) and modify its render_options function
to customise how <option> elements are created based on the available
choices.

Since you'd need to access the objects representing the widget choices
when rendering it, you'd have to pass the available choices to the
form field which uses the widget using the Category objects themselves
as the value, rather than a string representation of them, as you
would normally do.

Here's an example implementation which I think should do what you want:

http://dpaste.com/hold/56364/

Regards,
Jonathan.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to