-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
219 additions
and
16 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
app/comments/migrations/0002_alter_comment_options_newscomment.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,62 @@ | ||
# Generated by Django 4.2.6 on 2023-10-27 02:53 | ||
|
||
import uuid | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("core", "0004_alter_news_slug"), | ||
("comments", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="comment", | ||
options={"ordering": ["-added"], "verbose_name_plural": "trip comments"}, | ||
), | ||
migrations.CreateModel( | ||
name="NewsComment", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("content", models.TextField()), | ||
( | ||
"uuid", | ||
models.UUIDField(default=uuid.uuid4, editable=False, unique=True), | ||
), | ||
("added", models.DateTimeField(auto_now_add=True)), | ||
("updated", models.DateTimeField(auto_now=True)), | ||
( | ||
"article", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="comments", | ||
to="core.news", | ||
), | ||
), | ||
( | ||
"author", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name_plural": "news comments", | ||
"ordering": ["-added"], | ||
}, | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
app/comments/migrations/0003_rename_article_newscomment_news.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,17 @@ | ||
# Generated by Django 4.2.6 on 2023-10-27 03:10 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("comments", "0002_alter_comment_options_newscomment"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="newscomment", | ||
old_name="article", | ||
new_name="news", | ||
), | ||
] |
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,24 +1,46 @@ | ||
import uuid | ||
|
||
from core.models import News | ||
from django.conf import settings | ||
from django.db import models | ||
from logger.models import Trip | ||
|
||
|
||
class Comment(models.Model): | ||
class BaseComment(models.Model): | ||
content = models.TextField() | ||
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | ||
trip = models.ForeignKey(Trip, on_delete=models.CASCADE, related_name="comments") | ||
|
||
uuid = models.UUIDField(unique=True, editable=False, default=uuid.uuid4) | ||
added = models.DateTimeField(auto_now_add=True) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
|
||
class Comment(BaseComment): | ||
trip = models.ForeignKey(Trip, on_delete=models.CASCADE, related_name="comments") | ||
|
||
class Meta: | ||
ordering = ["-added"] | ||
verbose_name_plural = "trip comments" | ||
|
||
def __str__(self): | ||
return f"Comment by {self.author} on {self.trip}" | ||
|
||
def get_absolute_url(self): | ||
return self.trip.get_absolute_url() | ||
|
||
|
||
class NewsComment(BaseComment): | ||
news = models.ForeignKey(News, on_delete=models.CASCADE, related_name="comments") | ||
|
||
class Meta: | ||
ordering = ["-added"] | ||
verbose_name_plural = "news comments" | ||
|
||
def __str__(self): | ||
return f"Comment by {self.author} on {self.article.title}" | ||
|
||
def get_absolute_url(self): | ||
return self.article.get_absolute_url() |
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
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
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