-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: crate comment app and integrate django_ltree_2
- Loading branch information
1 parent
bc7f8d7
commit 94d793b
Showing
24 changed files
with
386 additions
and
92 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Comment | ||
|
||
# Register your models here. | ||
|
||
|
||
@admin.register(Comment) | ||
class CommentAdmin(admin.ModelAdmin): | ||
list_display = ('quibbler', 'content', 'created_at') | ||
search_fields = ('quibbler__username', 'content') |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CommentConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'apps.comment' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Generated by Django 5.1.4 on 2024-12-13 10:36 | ||
|
||
import django.contrib.postgres.indexes | ||
import django.db.models.deletion | ||
import django_ltree.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('user', '0003_alter_profile_username'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
( | ||
'id', | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name='ID', | ||
), | ||
), | ||
( | ||
'created_at', | ||
models.DateTimeField(auto_now_add=True, verbose_name='create at'), | ||
), | ||
('path', django_ltree.fields.PathField(unique=True)), | ||
('content', models.TextField(verbose_name='content')), | ||
( | ||
'downvotes', | ||
models.ManyToManyField( | ||
blank=True, | ||
related_name='downvotes', | ||
to='user.profile', | ||
verbose_name='downvotes', | ||
), | ||
), | ||
( | ||
'quibbler', | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to='user.profile', | ||
verbose_name='quibbler', | ||
), | ||
), | ||
( | ||
'upvotes', | ||
models.ManyToManyField( | ||
blank=True, | ||
related_name='upvotes', | ||
to='user.profile', | ||
verbose_name='upvotes', | ||
), | ||
), | ||
], | ||
options={ | ||
'verbose_name': 'Comment', | ||
'verbose_name_plural': 'Comments', | ||
'indexes': [ | ||
django.contrib.postgres.indexes.GistIndex( | ||
fields=['path'], name='comment_com_path_d1388c_gist' | ||
) | ||
], | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from django.contrib.postgres import indexes as idx | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from django_ltree.models import TreeModel | ||
|
||
from apps.user.models import Profile | ||
from common.mixins.model_mixins import CreatedAtMixin | ||
|
||
# Create your models here. | ||
|
||
|
||
class Comment(CreatedAtMixin, TreeModel): | ||
quibbler = models.ForeignKey( | ||
Profile, on_delete=models.CASCADE, verbose_name=_('quibbler') | ||
) | ||
content = models.TextField(_('content')) | ||
upvotes = models.ManyToManyField( | ||
Profile, related_name='upvotes', blank=True, verbose_name=_('upvotes') | ||
) | ||
downvotes = models.ManyToManyField( | ||
Profile, related_name='downvotes', blank=True, verbose_name=_('downvotes') | ||
) | ||
|
||
@property | ||
def children_count(self): | ||
return self.children().count() | ||
|
||
def __str__(self) -> str: | ||
return f"Comment by {self.quibbler.username}" | ||
|
||
class Meta: # pyright: ignore | ||
indexes = [idx.GistIndex(fields=['path'])] | ||
verbose_name = 'Comment' | ||
verbose_name_plural = 'Comments' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 5.1.4 on 2024-12-13 02:45 | ||
|
||
import dynamic_filenames | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('quiblet', '0002_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='quib', | ||
name='cover', | ||
field=models.ImageField( | ||
blank=True, | ||
null=True, | ||
upload_to=dynamic_filenames.FilePattern( | ||
filename_pattern='cover/{uuid:s}{ext}' | ||
), | ||
verbose_name='cover', | ||
), | ||
), | ||
] |
53 changes: 53 additions & 0 deletions
53
.../quiblet/migrations/0004_remove_quib_dislikes_remove_quib_likes_quib_comments_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Generated by Django 5.1.4 on 2024-12-13 10:36 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('comment', '0001_initial'), | ||
('quiblet', '0003_quib_cover'), | ||
('user', '0003_alter_profile_username'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='quib', | ||
name='dislikes', | ||
), | ||
migrations.RemoveField( | ||
model_name='quib', | ||
name='likes', | ||
), | ||
migrations.AddField( | ||
model_name='quib', | ||
name='comments', | ||
field=models.ManyToManyField( | ||
blank=True, | ||
related_name='comments', | ||
to='comment.comment', | ||
verbose_name='comments', | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='quib', | ||
name='downvotes', | ||
field=models.ManyToManyField( | ||
blank=True, | ||
related_name='downvoted_quibs', | ||
to='user.profile', | ||
verbose_name='downvotes', | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='quib', | ||
name='upvotes', | ||
field=models.ManyToManyField( | ||
blank=True, | ||
related_name='upvoted_quibs', | ||
to='user.profile', | ||
verbose_name='upvotes', | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.