samedi 17 octobre 2020

IntegrityError at /admin/main/post/add/ NOT NULL constraint failed: main_post.status

How fix this? This after when i create new post and when i press button 'add'

It looks like your post is mostly code; please add some more details. Why stackoverflow ask this?

#models.py
from django.db import models
from django.contrib.auth.models import User


class Post(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=255)
    author = models.ForeignKey(User, on_delete= models.CASCADE,related_name='blog_posts')
    content = models.TextField()
    
    created_on = models.DateTimeField(auto_now_add=True)
    updated_on = models.DateTimeField(auto_now= True)

    def __str__(self):
        return self.title

#admin.py
from django.contrib import admin
from .models import Post

class PostAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',), }

admin.site.register(Post,PostAdmin)



Aucun commentaire:

Enregistrer un commentaire