On Wed, 2009-04-22 at 04:42 -0700, Konstantin S wrote:
> On Apr 22, 1:51 pm, Tom Evans <tevans...@googlemail.com> wrote:
> > On Tue, 2009-04-21 at 21:20 +0400, Konstantin S wrote:
> > > Hello!
> >
> > > In my model I have dynamically generated checkbox fields that look like 
> > > this:
> >
> > > boxes = forms.ModelMultipleChoiceField(queryset=Box.objects.all(),
> > > widget=forms.CheckboxSelectMultiple)
> >
> > > The problem is that in the web-interface I've got a long flat list of
> > > checkboxes and it doesn't look very nice from a design point of view.
> > > What I want is to split it into two or more columns, but I am not a
> > > web developer and my knowledge in html and css is very limited. I'd
> > > try to find a solution for this problem if I were given some hints
> > > where to start. Please give me such hints.
> >
> > Write your own widget class to output the required inputs in the manner
> > you want. Check out how CheckboxSelectMultiple.render() is implemented
> > in django/forms/widgets.py
> >
> 
> Thanks, Tom!
> 
> Your advise really seems to be a solution for my problem. BTW is there
> any official documentation for writing custom widgets ? Couldn't find
> any :(
> 

Theres not really any that I could find, mainly the docs seem to suggest
the best way to customize your widget is to pass in additional
attributes, but that doesn't help in truly complex forms. 

The best documentation is always the source, widgets.py is only ~600
lines, and most of the logic is fairly self contained within that file
(you don't, for example, need to know how form.Fields integrate into the
logic, or how data is bound to the field from a post or initial data, as
the values are passed into the render() function of the widget for you.)

(On the other hand, if you _can_ get the result you want with just some
nice CSS, I'd go for that! Don't make a custom widget unless you have
to :)

Cheers

Tom


--~--~---------~--~----~------------~-------~--~----~
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