I
I
i_ikigai2021-09-28 00:45:21
Django
i_ikigai, 2021-09-28 00:45:21

How to change the status of the model using the button?

There is a model with two statuses

class Post(models.Model):
STATUS_CHOICES = (
        ('draft', 'Draft'),
        ('published', 'Published'),
    )
    title = models.CharField(_('Покупатель'), max_length=50)
    slug = models.SlugField(unique=True, null=True, blank=True)
    status = models.CharField(max_length=10,
                              choices=STATUS_CHOICES,
                              default='published')

On the single post output page, how to add a button to change the post status?
class DetailPageView(View):
    def get(self, request, pk):
        post = Post.objects.get(id=pk)
        return render(request, 'updocks/adddoc/detail.html', {'post': post})

{% block content %}
    <h1>{{ post.title }}</h1>
    {{ post.body|linebreaks }}
{% endblock %}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question