Dear List, I'm a bit stuck on a problem. I googled a lot, but didn't find an answer.
I have a "Loan" model and a "Payment" model. In the admin, I display the payments for each loan in inlines. I want payements that are more than 3 days old to be displayed as readonly, as they are considered to be archived. I don't need it to be secure (I'm doing checks in the model save/delete methods anyway), but I need to have them display with the readonly html attribute so that they aren't too easily modified. Here's what I've got so far : class PaymentFormSet(BaseInlineFormSet): @cached_property def forms(self): forms = super().forms for form in forms: if form.instance.is_archived: form.base_fields['amount'].widget.attrs['readonly'] = True form.base_fields['date'].widget.attrs['readonly'] = True return forms class PaymentInline(admin.TabularInline): model = Payment formset = PaymentFormSet ... This raises no exception (which means the widget.attrs dictionarry is correctly referenced), but the attribute doesn't display. The form is exactly the same than without... I tried some to replace the widget too : ... form.base_fields['amount'].widget = TextInput(attrs={'readonly':True}) ... and the field : ... form.base_fields['amount'] = django.forms.CharField(widget=TextInput(attrs={'readonly':True})) ... But all those don't produce any effect. I considered other options (InlineModelAdmin's readonly_fields...) but had even more problems (as then the data isn't posted, I was getting validation errors), and I think it's not the right way to go. After that, I'd love to be able to hide the "delete" button too... Thank you very much in advance !! Olivier -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAExk7p03CDmrN%2BfOiD47Ngu7JTAL13Q0D1Kntautuz__KCc%2BWg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.