im newbie in django..
i dont know why it’s raise an error
its models.py codes
class PublishManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(status=Post.Status.Draft)
# Create your models here.
# First Model
class Post(models.Model):
class Status(models.TextChoices):
Draft = 'Dr', "Draft"
Released = 'RL', "Released"
Rejected = 'RJ', "Rejected"
# Managers
objects = models.Manager()
Publishedss = PublishManager()
# Author
Author = models.ForeignKey(User, on_delete=models.CASCADE, related_name="up")
# information
title = models.CharField(max_length=200)
description = models.TextField(max_length=9000)
Slug = models.SlugField(max_length=250)
# Timing
published = models.DateTimeField(timezone.now)
created = models.DateTimeField(auto_now_add=True)
Updated = models.DateTimeField(auto_now=True)
# Status
Status = models.CharField(max_length=2, choices=Status.choices, default=Status.Draft)
# Sorting
class Meta:
ordering = ["-published"]
indexes = [
models.Index(fields=['-published'])
]
def __str__(self):
return self.title
raise an error
and it’s detail codes
def post_detail(request, id):
print(id)
posts1 = get_object_or_404(Post, id=id, status=Post.Status.Draft)
context = {
"Post": posts1
}
return render(request, "blog/detail.html", context)
AttributeError at /blog/post/1
‘DeferredAttribute’ object has no attribute ‘Draft’
Request Method: GET
Request URL: http://127.0.0.1:8000/blog/post/1
Django Version: 5.0.4
Exception Type: AttributeError
Exception Value:
‘DeferredAttribute’ object has no attribute ‘Draft’
Exception Location: D:PythonPythonProjectsproject1blogviews.py, line 24, in post_detail
Raised during: blog.views.post_detail
Python Executable: D:PythonPythonProjectsproject1venvbinpython.exe
Python Version: 3.11.7
Python Path:
[‘D:PythonPythonProjectsproject1’,
‘C:Program FilesJetBrainsPyCharm ‘
‘2023.3.5pluginspythonhelperspycharm’,
‘D:PythonPythonProjectsproject1’,
‘C:msys64ucrt64libpython311.zip’,
‘C:msys64ucrt64libpython3.11’,
‘C:msys64ucrt64libpython3.11lib-dynload’,
‘D:PythonPythonProjectsproject1venvlibpython3.11site-packages’]
Server time: Thu, 25 Apr 2024 08:14:02 +0000
Arash Raynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.