On Tue, Aug 2, 2011 at 3:47 PM, webcomm <rya...@gmail.com> wrote:
>> Have you simplified your example?
>
> The example I provided in the original post is the actual code in my
> models.py.  It's not simplified.
>
>> >>> class TestForm(ModelForm):
>>
>> ...   range = CharField(widget=HiddenInput)
>> ...   class Meta:
>> ...     model=Foo
>> ...>>> f=TestForm()
>> >>> f.as_p()
>>
>> u'<p><label for="id_name">Name:</label> <input type="text" name="name"
>> id="id_name" /><input type="hidden" name="range" id="id_range" /></p>'
>>
>> As you can see, the range field is clearly hidden.
>
> I get "CharField is not defined" when I try your code.  I find that I
> have to do forms.SomeField.  Maybe we're importing different things.
> In my models.py I have...
>
> from django.db import models
> from django import forms
> from django.forms import ModelForm
>
> I'm using django 1.3.
>
> -Ryan
>

Well, in the console I cannot be arsed to continually type
forms.SomeThing, so I imported * from django.forms, but this is
largely irrelevant.

You still haven't shown that it doesn't hide the field, eg by posting
the output of frm.as_p(), where as I have shown conclusively that it
does, so I think something else is going on here. Are you sure the
field 'itemid' exists on your model?

This is speculation, but I think you don't have a field called itemid
on your model, and so are creating an additional field called itemid,
which is hidden. You display the form, you don't see the new, hidden,
'itemid' field because it is hidden, but you do see your field which
is not called 'itemid', and you then think that the field is not
hidden.

It's not hard to test this, go to your django console, import the
form, instantiate it and call the as_p method. Do you have a hidden
field called 'itemid' or not?

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