> I think the basic issue is that there are some fields in the object
> that I'd like to display but not have editable, and it's not at all
> clear to me how to make that happen in the form processor. The values
> are dynamic, so they can't be in the template.

I often have this need so I created a custom widget where I just set
the readonly attribute on a TextInput widget:

class LabelWidget(forms.TextInput):
    def __init__(self, *args, **kwargs):
        attrs = kwargs.get('attrs', {})
        attrs['readonly'] = True
        if 'class' in attrs:
            attrs['class'] = attrs['class'] + ' label'
        else:
            attrs['class'] = 'label'
        super(LabelWidget, self).__init__(*args, **kwargs)

Then I use it in forms like this:

class AccountForm(forms.Form):
    name = forms.CharField(widget=LabelWidget)
    business = forms.CharField(widget=LabelWidget(attrs={'size': 5}))
    ...

I set/add 'label' to the CSS class so I can style these differently. I
used a custom widget over explicit "form.initial['field']" syntax in
my template so I could let the form lay itself out automatically
treating all fields the same way.

-Dave

On Dec 1, 1:45 pm, ChrisK <[EMAIL PROTECTED]> wrote:
> > I think you really need to explain what the real problem is that you're
> > trying to solve, because you're asking a question that is too specific.
>
> Fair enough. It's been several days, so I had to dredge a bit to
> remember :-)
>
> I think the basic issue is that there are some fields in the object
> that I'd like to display but not have editable, and it's not at all
> clear to me how to make that happen in the form processor. The values
> are dynamic, so they can't be in the template.
>
> I'm happy not to replicate the logic inside BoundField.as_widget(), if
> there's some way that the "correct" value is exposed to the
> template...
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to