Skip to content

Commit

Permalink
refactoring code
Browse files Browse the repository at this point in the history
RustamovAkrom committed Oct 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a1f9764 commit 4171447
Showing 9 changed files with 27 additions and 28 deletions.
6 changes: 3 additions & 3 deletions apps/blog/migrations/0005_post_slug.py
Original file line number Diff line number Diff line change
@@ -6,13 +6,13 @@
class Migration(migrations.Migration):

dependencies = [
('blog', '0004_alter_user_avatar'),
("blog", "0004_alter_user_avatar"),
]

operations = [
migrations.AddField(
model_name='post',
name='slug',
model_name="post",
name="slug",
field=models.SlugField(default=1, max_length=255, unique=True),
preserve_default=False,
),
6 changes: 3 additions & 3 deletions apps/blog/models.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ class User(AbstractUser, TimestempedAbstractModel):
@property
def post_count(self):
return self.posts.count


class Post(TimestempedAbstractModel):
title = models.CharField(max_length=120)
@@ -24,11 +24,11 @@ class Post(TimestempedAbstractModel):
author = models.ForeignKey("User", models.CASCADE, "posts")

def get_absolute_url(self):
return reverse("post_detail", kwargs={'slug': self.slug})
return reverse("post_detail", kwargs={"slug": self.slug})

def get_author_avatar_url(self):
return self.author.avatar.url

def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
4 changes: 2 additions & 2 deletions apps/blog/sitemaps.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,6 @@ class PostSitemap(Sitemap):

def items(self):
return Post.objects.all()

def lastmod(self, obj):
return obj.updated_at
return obj.updated_at
4 changes: 1 addition & 3 deletions apps/blog/views.py
Original file line number Diff line number Diff line change
@@ -120,9 +120,7 @@ class PostDetailPageView(CustomHtmxMixin, View):

def get(self, request, slug):
post = get_object_or_404(Post, slug=slug)
return render(
request, "blog/post_detail.html", {"post": post}
)
return render(request, "blog/post_detail.html", {"post": post})


class UserProfilePageView(CustomHtmxMixin, LoginRequiredMixin, View):
2 changes: 1 addition & 1 deletion apps/shared/admin.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from django.contrib import admin # noqa
from django.contrib import admin # noqa
3 changes: 1 addition & 2 deletions apps/shared/models.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
class TimestempedAbstractModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
abstract = True

2 changes: 1 addition & 1 deletion apps/shared/tests.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from django.test import TestCase # noqa
from django.test import TestCase # noqa
6 changes: 1 addition & 5 deletions config/settings.py
Original file line number Diff line number Diff line change
@@ -6,11 +6,7 @@

DEBUG = True

ALLOWED_HOSTS = [
"blog-post-see1.onrender.com",
"localhost",
"127.0.0.1"
]
ALLOWED_HOSTS = ["blog-post-see1.onrender.com", "localhost", "127.0.0.1"]

INSTALLED_APPS = [
"django.contrib.admin",
22 changes: 14 additions & 8 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import handler400, handler403, handler404, handler500 # noqa
from django.conf.urls import handler400, handler403, handler404, handler500 # noqa
from django.conf.urls.static import static
from . import settings

@@ -11,21 +11,27 @@


sitemaps = {
'posts': PostSitemap,
"posts": PostSitemap,
}

urlpatterns = [
path("admin/", admin.site.urls), path("", include("apps.blog.urls")),
path("admin/", admin.site.urls),
path("", include("apps.blog.urls")),
path("robots.txt", TemplateView.as_view(template_name="bunin/robots.txt")),
path("sitemap.xml", sitemap, {'sitemaps': sitemaps}, name="django.contrib.sitemaps.views.sitemap"),
path(
"sitemap.xml",
sitemap,
{"sitemaps": sitemaps},
name="django.contrib.sitemaps.views.sitemap",
),
]

if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


handler400 = "apps.shared.views.bad_request_view" # noqa
handler403 = "apps.shared.views.page_permission_denied_view" # noqa
handler404 = "apps.shared.views.page_not_found_view" # noqa
handler500 = "apps.shared.views.server_error_view" # noqa
handler400 = "apps.shared.views.bad_request_view" # noqa
handler403 = "apps.shared.views.page_permission_denied_view" # noqa
handler404 = "apps.shared.views.page_not_found_view" # noqa
handler500 = "apps.shared.views.server_error_view" # noqa

0 comments on commit 4171447

Please sign in to comment.