Skip to content

Commit

Permalink
Merge pull request #14 from RustamovAkrom/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
RustamovAkrom authored Nov 14, 2024
2 parents e03187c + be06531 commit 1f18229
Show file tree
Hide file tree
Showing 29 changed files with 545 additions and 405 deletions.
130 changes: 65 additions & 65 deletions apps/blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
# Generated by Django 5.1.1 on 2024-11-13 12:31

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('title', models.CharField(db_index=True, max_length=120, verbose_name='title')),
('slug', models.SlugField(max_length=255, unique=True, verbose_name='slug')),
('status', models.CharField(choices=[('df', 'Draft'), ('pb', 'Published')], default='df', max_length=2, verbose_name='status')),
('description', models.CharField(blank=True, max_length=300, null=True, verbose_name='description')),
('content', models.TextField(verbose_name='content')),
('publisher_at', models.DateField(verbose_name='publisher at')),
('is_active', models.BooleanField(default=True, verbose_name='active')),
('watching', models.BigIntegerField(default=0, verbose_name='watching')),
],
options={
'verbose_name': 'Post',
'verbose_name_plural': 'Posts',
'db_table': 'posts',
},
),
migrations.CreateModel(
name='PostComment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('message', models.TextField(verbose_name='message')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='PostCommentLike',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='PostDislike',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='PostLike',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
]
# Generated by Django 5.1.1 on 2024-11-13 12:31

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('title', models.CharField(db_index=True, max_length=120, verbose_name='title')),
('slug', models.SlugField(max_length=255, unique=True, verbose_name='slug')),
('status', models.CharField(choices=[('df', 'Draft'), ('pb', 'Published')], default='df', max_length=2, verbose_name='status')),
('description', models.CharField(blank=True, max_length=300, null=True, verbose_name='description')),
('content', models.TextField(verbose_name='content')),
('publisher_at', models.DateField(verbose_name='publisher at')),
('is_active', models.BooleanField(default=True, verbose_name='active')),
('watching', models.BigIntegerField(default=0, verbose_name='watching')),
],
options={
'verbose_name': 'Post',
'verbose_name_plural': 'Posts',
'db_table': 'posts',
},
),
migrations.CreateModel(
name='PostComment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('message', models.TextField(verbose_name='message')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='PostCommentLike',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='PostDislike',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='PostLike',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
]
2 changes: 1 addition & 1 deletion apps/blog/sitemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PostSitemap(Sitemap):
priority = 0.9

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

def lastmod(self, obj):
return obj.updated_at
28 changes: 17 additions & 11 deletions apps/blog/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db.models import QuerySet
from django.db.models import Q
from django.core.paginator import Paginator, Page, EmptyPage, PageNotAnInteger

from .models import PostLike, PostDislike, Post, PostComment
Expand All @@ -7,19 +8,24 @@
def get_search_model_queryset(
model_queryset: QuerySet, search_query: str = None
) -> QuerySet:
if search_query is None:
if not search_query:
return model_queryset

search_for_title = model_queryset.filter(title__icontains=search_query)
if not search_for_title:
search_for_content = model_queryset.filter(content__icontains=search_query)
if not search_for_content:
queryset = search_for_content
else:
queryset = search_for_content
else:
queryset = search_for_title
return queryset
search_query = model_queryset.filter(
Q(title__icontains=search_query) | Q(description__icontains=search_query) | Q(content__icontains=search_query)
)

return search_query
# search_for_title = model_queryset.filter(title__icontains=search_query)
# if not search_for_title:
# search_for_content = model_queryset.filter(content__icontains=search_query)
# if not search_for_content:
# queryset = search_for_content
# else:
# queryset = search_for_content
# else:
# queryset = search_for_title
# return queryset


def get_pagination_obj(model_queryset: QuerySet, page: int = 1, size: int = 4) -> Page:
Expand Down
Loading

0 comments on commit 1f18229

Please sign in to comment.