I created a model on django for blog posts. Each post has two status choices: Publish or Draft. How can i change Publish to Published after the post is saved?
This is my code:
from django.db import models
from django.contrib.auth.models import User
Create your models here.
STATUS = ( (0,"Draft"),
(1,"Publish"), )
class Post(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, unique=True)
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts')
updated_on = models.DateTimeField(auto_now=True)
content = models.TextField()
created_on = models.DateTimeField(auto_now_add=True)
status = models.Integer(choices=STATUS, default=0)
class Meta:
ordering = ['-created_on']
def __str__(self):
return self.title
from django.contrib import admin from .models import *
Register your models here
class PostAdmin(admin.ModelAdmin):
list_display = ('title','slug','status','created_on',)
list_filter = ("status",)
search_fields = ('title', 'content')
prepopulated_fields = {'slug': ('title',)}
admin.site.register(Post,PostAdmin)