You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have "all fields" form with one field marked as "required" and "readonly_fields" hiding some of them on changeform admin page.
class SeasonForm(ModelForm):
class Meta:
model = models.Season
fields = '__all__'
parent = ModelChoiceField(queryset=..., required=True)
class SeasonAdmin(ModelAdmin):
form = SeasonForm
readonly_fields = ('parent',)
Pressing "save" on an existing valid object we got "invisible" error:
That's because "parent" field is still required and readonly at the same time.
So, django renders it without any form input and no value is passed in POST request.
But, we can't reproduce it with django-admin-smoke-based tests, because "readonly_fields" are not taken into account.
Below is a fix that makes our error reproducible:
def get_form_data_from_response(self, r: HttpResponseBase
) -> dict[str, Any]:
data = super().get_form_data_from_response(r)
cd = getattr(r, 'context_data')
readonly_modeladmin_fields = cd['adminform'].readonly_fields
for f in readonly_modeladmin_fields:
data.pop(f, None)
return data
The text was updated successfully, but these errors were encountered:
We have "all fields" form with one field marked as "required" and "readonly_fields" hiding some of them on changeform admin page.
Pressing "save" on an existing valid object we got "invisible" error:

That's because "parent" field is still required and readonly at the same time.
So, django renders it without any form input and no value is passed in POST request.
But, we can't reproduce it with django-admin-smoke-based tests, because "readonly_fields" are not taken into account.
Below is a fix that makes our error reproducible:
The text was updated successfully, but these errors were encountered: