read only/hidden form fields

23 views
Skip to first unread message

c.po...@bangor.ac.uk

unread,
Sep 26, 2005, 12:30:21 PM9/26/05
to Django users
Hi

I want to be able to pass the values of certain form fields to the form
and have them rendered as read only or hidden fields.

Is there an elegant way of doing this?

Thanks
Charlotte

c.po...@bangor.ac.uk

unread,
Sep 28, 2005, 4:36:18 AM9/28/05
to Django users
Found a really tidy way of doing this.

Created a new css style based on the Django Wide and Collapse styles
calld Hide

/* CUSTOM TYPE hide */
.hide label { width:15em !important; }
.colM .hide select { visibility: hidden; }
fieldset.hide * { display:none; }

Then in the model simply grouped together the fields I wanted to hide
and applied the Hide class to that fieldset

class Question(meta.Model):
fields = (
meta.ForeignKey(Student),
meta.ForeignKey(Group),
meta.ForeignKey(QuestionType),
meta.CharField('question', maxlength=250),
)

admin = meta.Admin(save_as=True,
fields = (
(None, {'fields': ('question', 'questiontype_id')}),
('Hidden Info', {'fields': ('student_id', 'group_id', ),
'classes': 'hide'}),
),

)

Reply all
Reply to author
Forward
0 new messages