Model Post
has the boolean field moderation
, which is intended for publishing after approval by admin users (which have user.is_staff
as True
.
There is a page "Post update", where an user (the author of the post) and admin users can updated the post info.
I want that the field moderation
(which is a checkbox) is shown only if the user is an admin (user.is_staff == True
).
models.py
class Post(models.Model):
...
moderation = models.BooleanField(default=True)
...
forms.py
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = ['title', 'body', 'logo']
views.py
class PostUpdateView(PermissionRequiredMixin, UpdateView):
model = Post
fields = ['title', 'body', 'logo']
permission_required = 'post.can_mark_returned'
post_form.html
{% extends "base_generic.html" %}
{% block content %}
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Submit" />
</form>
{% endblock %}