Description
The Post.get_absolute_url() method in src/blog/models.py references self.slug, but the Post model has no slug field defined. Calling this method on any Post instance raises an AttributeError.
Location
File: src/blog/models.py
Class: Post
Method: get_absolute_url()
Branch: develop
Current Code
class Post(TimeStampedModel):
id = models.BigAutoField(primary_key=True)
title = models.CharField(max_length=200)
status = models.CharField(...)
author = models.ForeignKey(...)
body = models.TextField()
categories = models.ManyToManyField(...)
images = models.ManyToManyField(...)
# No 'slug' field!
def get_absolute_url(self):
return f"/memories/{self.slug}/" # AttributeError: 'Post' object has no attribute 'slug'
Problem
The Post model does not define a slug field, but get_absolute_url() uses self.slug. Any code (templates, admin, sitemaps) that calls post.get_absolute_url() will raise:
AttributeError: 'Post' object has no attribute 'slug'
Suggested Fix
Either add a slug field to the Post model:
slug = models.SlugField(unique=True, max_length=200)
Or change get_absolute_url() to use the id field:
def get_absolute_url(self):
return f"/memories/{self.id}/"
Severity
High — Any call to get_absolute_url() on a Post instance raises AttributeError.
Description
The
Post.get_absolute_url()method insrc/blog/models.pyreferencesself.slug, but thePostmodel has noslugfield defined. Calling this method on anyPostinstance raises anAttributeError.Location
File:
src/blog/models.pyClass:
PostMethod:
get_absolute_url()Branch:
developCurrent Code
Problem
The
Postmodel does not define aslugfield, butget_absolute_url()usesself.slug. Any code (templates, admin, sitemaps) that callspost.get_absolute_url()will raise:Suggested Fix
Either add a
slugfield to thePostmodel:Or change
get_absolute_url()to use theidfield:Severity
High — Any call to
get_absolute_url()on aPostinstance raisesAttributeError.