Why is the URL not working after adding foreignkey field to model?

I’m creating a blog application and I added a category for its blog posts. When adding a new category it can be can be done without any problem. But the problem is I can’t find posts for a specific category ID and get an error like

Field ‘id’ expected a number but got ‘health’

But before I updated field category charafield to forenkeyfied it worked without any problem.

Here is my code:

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 = SummernoteTextField(blank=True, null=True)
    created_on = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(choices=STATUS, default=0)
    image = models.ImageField(upload_to='images',null=True, blank=True)
    category = models.ForeignKey('blog.category', on_delete=models.SET_NULL, null=True, blank=True)
 class category(models.Model):
    name = models.CharField(max_length=80)
    def __str__(self):
        return self.name


def CategoryView(request, cats):
    category_posts = Post.objects.filter(category=cats.replace('-', ' '))
    return render(request, 'categories.html', {'cats':cats.replace('-', ' '), 'category_posts':category_posts})


class PostForm(forms.ModelForm):
    category = forms.ModelChoiceField(queryset=category.objects.all().order_by('name'))
    class Meta:
        model = Post
        fields = ('title', 'category','author', 'content', 'image','status')


You didn’t share the full traceback but the error likely is caused by this line

Post.objects.filter(category=cats.replace('-', ' '))

You are filtering against the category foreign key using a string hence the error.

What you intended seems to be to filter against the category name:

Post.objects.filter(category__name=cats.replace('-', ' '))