1

I'm trying to use the new readonly_fields in a ModelForm.

class TrainingAddForm(forms.ModelForm):
    class Meta:
        model = TrainingTasks
        readonly_fields = ('trainee_signed','trainee_signed_date')

But this does not work. Am I missing something or is this not possible?

normic
  • 1,388
  • 3
  • 24
  • 36

2 Answers2

0

As per the documentation, this is a member of admin.ModelAdmin, not forms.ModelForm. Your admin form needs to inherit from admin.ModelAdmin in order for you to have access to the readonly_fields option.

Edit: I mis-read the original question, I thought you were trying to use the field within Django's supplied admin app. However, as seen in my initial response, this option is only available for classes that inherit from admin.ModelAdmin — you will not be able to use it via forms.ModelForm.

Andrew
  • 12,821
  • 2
  • 26
  • 18
0

For doing it in a form, see In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?

Community
  • 1
  • 1
Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148