0

I am trying to set a readonly attribute to this specific field in django. What I hope to accomplish is the field's data shows but it cant be changed. How do I go about this? Below is what I've tried and isn't working for me.

class editcartform(ModelForm):

  class Meta:
     model = signedup
     exclude = ['sessionid', 'price', 'paid', 'orderid', 'dancer_1_level', 'dancer_2_level', 'dancer_2_sex', 'dancer_1_sex']
     widgets = { 
        'comp_name':Textarea(attrs={'readonly'}),
    }
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
user3806832
  • 663
  • 9
  • 22
  • possible duplicate of [In a django form, How to make a field readonly (or disabled) so that it cannot be edited?](http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-b) – Sunny Sharma Jul 24 '14 at 04:30
  • http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-b – Runcorn Jul 24 '14 at 04:31
  • Ive already tried, that, It's still editable – user3806832 Jul 24 '14 at 04:37

1 Answers1

0
'comp_name':Textarea(attrs={'readonly':'readonly'}),

or

'comp_name':Textarea(attrs={'disabled':'disabled'}),

It may change depends on what you want.

  • When I add that I get a number (it is a foreign field) do you know how i can force it to show the item it points to in readable terms instead of just a number? – user3806832 Jul 25 '14 at 07:10