-
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: move quib to separate app and update settings.py
- Loading branch information
1 parent
ae53828
commit 94e36f2
Showing
10 changed files
with
181 additions
and
54 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,9 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Quib | ||
|
||
|
||
@admin.register(Quib) | ||
class QuibAdmin(admin.ModelAdmin): | ||
list_display = ('title', 'quiblet', 'quibber', 'is_public', 'created_at') | ||
search_fields = ('title', 'quiblet__name', 'quibber__name') |
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 QuibConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'apps.quib' |
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,90 @@ | ||
# Generated by Django 5.1.3 on 2024-12-07 04:12 | ||
|
||
import django.db.models.deletion | ||
import shortuuid.django_fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('quiblet', '0003_delete_quib'), | ||
('user', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Quib', | ||
fields=[ | ||
( | ||
'created_at', | ||
models.DateTimeField(auto_now_add=True, verbose_name='create at'), | ||
), | ||
('is_public', models.BooleanField(default=True, verbose_name='is public')), | ||
( | ||
'id', | ||
shortuuid.django_fields.ShortUUIDField( | ||
alphabet='abcdefghijklmnopqrstuvwxyz0123456789', | ||
editable=False, | ||
length=7, | ||
max_length=7, | ||
prefix='', | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name='id', | ||
), | ||
), | ||
('title', models.CharField(max_length=255, verbose_name='title')), | ||
( | ||
'slug', | ||
models.SlugField( | ||
blank=True, editable=False, max_length=25, verbose_name='slug' | ||
), | ||
), | ||
('content', models.TextField(verbose_name='content')), | ||
( | ||
'dislikes', | ||
models.ManyToManyField( | ||
blank=True, | ||
related_name='disliked_quibs', | ||
to='user.profile', | ||
verbose_name='dislikes', | ||
), | ||
), | ||
( | ||
'likes', | ||
models.ManyToManyField( | ||
blank=True, | ||
related_name='liked_quibs', | ||
to='user.profile', | ||
verbose_name='likes', | ||
), | ||
), | ||
( | ||
'quibber', | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name='quibs', | ||
to='user.profile', | ||
verbose_name='quibber', | ||
), | ||
), | ||
( | ||
'quiblet', | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name='quibs', | ||
to='quiblet.quiblet', | ||
verbose_name='quiblet', | ||
), | ||
), | ||
], | ||
options={ | ||
'verbose_name': 'Quib', | ||
'verbose_name_plural': 'Quibs', | ||
'ordering': ['-created_at'], | ||
}, | ||
), | ||
] |
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,46 @@ | ||
from django.db import models | ||
from django.utils.text import slugify | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from apps.quiblet.models import Quiblet | ||
from apps.user.models import Profile | ||
from common.mixins import CreatedAtMixin, IsPublicMixin, ShortUUIDIdMixin | ||
|
||
|
||
class Quib(CreatedAtMixin, IsPublicMixin, ShortUUIDIdMixin): | ||
quiblet = models.ForeignKey( | ||
Quiblet, | ||
related_name='quibs', | ||
verbose_name=_('quiblet'), | ||
on_delete=models.CASCADE, | ||
) | ||
quibber = models.ForeignKey( | ||
Profile, | ||
related_name='quibs', | ||
verbose_name=_('quibber'), | ||
on_delete=models.CASCADE, | ||
) | ||
title = models.CharField(_('title'), max_length=255) | ||
slug = models.SlugField(_('slug'), editable=False, max_length=25, blank=True) | ||
content = models.TextField(_('content')) | ||
likes = models.ManyToManyField( | ||
Profile, related_name='liked_quibs', blank=True, verbose_name=_('likes') | ||
) | ||
dislikes = models.ManyToManyField( | ||
Profile, related_name='disliked_quibs', blank=True, verbose_name=_('dislikes') | ||
) | ||
|
||
def save(self, *args, **kwargs): | ||
"""Override save method to slugify title.""" | ||
if not self.slug: | ||
self.slug = slugify(self.title[:25]) | ||
|
||
super(Quib, self).save(*args, **kwargs) | ||
|
||
def __str__(self): | ||
return f'{self.pk}/{self.slug}' | ||
|
||
class Meta: # type: ignore | ||
verbose_name = 'Quib' | ||
verbose_name_plural = 'Quibs' | ||
ordering = ['-created_at'] |
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 |
---|---|---|
@@ -1,15 +1,9 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Quib, Quiblet | ||
from .models import Quiblet | ||
|
||
|
||
@admin.register(Quiblet) | ||
class QuibletAdmin(admin.ModelAdmin): | ||
list_display = ('name', 'is_public', 'created_at') | ||
search_fields = ('name',) | ||
|
||
|
||
@admin.register(Quib) | ||
class QuibAdmin(admin.ModelAdmin): | ||
list_display = ('title', 'quiblet', 'quibber', 'is_public', 'created_at') | ||
search_fields = ('title', 'quiblet__name', 'quibber__name') |
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,16 @@ | ||
# Generated by Django 5.1.3 on 2024-12-07 04:11 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('quiblet', '0002_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name='Quib', | ||
), | ||
] |
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