Skip to content

Commit

Permalink
Added canonical URLs for models
Browse files Browse the repository at this point in the history
  • Loading branch information
yahyaaly151989 committed Aug 20, 2023
1 parent 51e3f20 commit fa70c44
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Binary file modified Module02/mysite/blog/__pycache__/models.cpython-311.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions Module02/mysite/blog/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse

class Post(models.Model):

Expand All @@ -25,3 +26,9 @@ class Meta:

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse("blog:post_detail", args=[
self.id
])

2 changes: 1 addition & 1 deletion Module02/mysite/blog/templates/blog/post/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h1>My Blog</h1>
{% for post in posts %}
<h2>
<a href="{% url 'blog:post_detail' post.id %}">
<a href="{{post.get_absolute_url}}">
{{ post.title }}
</a>
</h2>
Expand Down

0 comments on commit fa70c44

Please sign in to comment.