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

Draft : Make Template.template_file read-only on edition #22

Open
wants to merge 1 commit 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
7 changes: 7 additions & 0 deletions template_model/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions template_model/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this commented out code.

content = forms.CharField(widget=forms.Textarea, required=False)

class Meta:
Expand All @@ -24,4 +24,4 @@ def clean(self):
name=cleaned_data['name'])
else:
cleaned_data.pop('content')
return cleaned_data
return cleaned_data