从管理员提交 post 时,它给了我这样的东西 Select 一个有效的选择不是可用的选择之一

while submitting post from admin it gives me something like this Select a valid choice is not one of the available choices

我正在尝试提供帖子类别选择,一切正常,但如果我从管理面板添加帖子,我会收到类似这样的错误

Select a valid choice. SSC is not one of the available choices.

this is my Posts/models.py

from django.db import models
from django.core.validators import FileExtensionValidator
# Create your models here.


CATEGORIES = (
        ('SSC', 'SSCQUESTION'),
        ('CAT', 'CATQUESTION'),
    )


class Category(models.Model):
    title = models.CharField(max_length = 120, verbose_name="Title" )
    updated_at = models.DateTimeField(auto_now_add=True, verbose_name="Updated at")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="Created at")
    class Meta:
        verbose_name = "Category"
        verbose_name_plural = "Categories"
        ordering = ['title']
    def __str__(self):
        return self.title



class Posts(models.Model):
    title = models.CharField(max_length=60)
    file_upload = models.FileField(null= True, blank=True, validators=[FileExtensionValidator(['pdf'])])
    content = models.TextField()
    category = models.ForeignKey(Category, null= True,verbose_name="Category", on_delete=models.CASCADE,choices = CATEGORIES)
    updated = models.DateTimeField(auto_now=True, auto_now_add=False)
    timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
    
    # class Meta:
    #     verbose_name = "Post"
    #     verbose_name_plural = "Posts"
    #     ordering = ['-created_at']


    def __unicode__(self):
        return self.title 

    def __str__(self):
        return self.title
    

在管理面板中会出现这样的错误

删除选项

category = models.ForeignKey(Category, null= True,verbose_name="Category", on_delete=models.CASCADE)

转到管理面板中的类别 table 并在那里创建一些类别。这些类别现在将填充在 Post 创建页面

的下拉列表中