From 8991ac4d374fc34dcb62820361f7825a64aac6d0 Mon Sep 17 00:00:00 2001 From: Paul Florence Date: Thu, 9 Sep 2021 15:16:35 +0200 Subject: [PATCH] Make Template.template_file read-only on modify However you can still specify the template at creation. This commit will allow to automate upgrading template files managed by Makina corpus. --- template_model/admin.py | 7 +++++++ template_model/forms.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/template_model/admin.py b/template_model/admin.py index eec2109..429db3d 100644 --- a/template_model/admin.py +++ b/template_model/admin.py @@ -7,6 +7,13 @@ class TemplateAdmin(admin.ModelAdmin): form = TemplateForm list_display = ('name', 'added', 'updated') + readonly_fields = ('template_file',) + def get_readonly_fields(self, request, obj=None): + # Allows to specify the template file at creation, but disable it on change forms. + if obj: + return self.readonly_fields + else: + return [] admin.site.register(Template, TemplateAdmin) diff --git a/template_model/forms.py b/template_model/forms.py index 4707f1d..7d3259f 100644 --- a/template_model/forms.py +++ b/template_model/forms.py @@ -5,7 +5,7 @@ class TemplateForm(forms.ModelForm): - template_file = forms.FileField(required=False, allow_empty_file=True) + #template_file = forms.FileField(required=False, allow_empty_file=True) content = forms.CharField(widget=forms.Textarea, required=False) class Meta: @@ -24,4 +24,4 @@ def clean(self): name=cleaned_data['name']) else: cleaned_data.pop('content') - return cleaned_data + return cleaned_data \ No newline at end of file