Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history form renders incorrect if readonly (and pre-commit-ci) #1410

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
rev: 24.8.0
hooks:
- id: black
language_version: python3.8
language_version: python3.9

- repo: https://github.com/pycqa/flake8
rev: 7.1.1
Expand Down
13 changes: 10 additions & 3 deletions simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.contrib import admin
from django.contrib.admin import helpers
from django.contrib.admin.utils import unquote
from django.contrib.admin.utils import flatten_fieldsets, unquote
from django.contrib.auth import get_permission_codename, get_user_model
from django.core.exceptions import PermissionDenied
from django.db.models import QuerySet
Expand Down Expand Up @@ -240,11 +240,18 @@ def history_form_view(self, request, object_id, version_id, extra_context=None):
else:
form = form_class(instance=obj)

fieldsets = self.get_fieldsets(request, obj)

if object_id and not self.has_change_permission(request, obj):
readonly_fields = flatten_fieldsets(fieldsets)
else:
readonly_fields = self.get_readonly_fields(request, obj)

admin_form = helpers.AdminForm(
form,
self.get_fieldsets(request, obj),
fieldsets,
self.prepopulated_fields,
self.get_readonly_fields(request, obj),
readonly_fields,
model_admin=self,
)

Expand Down
Loading