Skip to content

Commit

Permalink
refactor(animes, mangas): add new fields, fix issues with new features
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronejosee committed Jun 7, 2024
1 parent d385057 commit 8610ec1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
4 changes: 3 additions & 1 deletion apps/animes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class Anime(BaseModel, SlugMixin):
choices=StatusChoices.choices,
default=StatusChoices.AIRING,
)
release = models.DateField(_("release"))
aired_from = models.DateField(_("aired from"))
aired_to = models.DateField(_("aired to"), blank=True, null=True)
producers = models.ManyToManyField(
Producer,
limit_choices_to={
Expand Down Expand Up @@ -178,6 +179,7 @@ class Anime(BaseModel, SlugMixin):

# is_publishing = models.BooleanField(_("is_publishing"), default=False)
# premiered = season + year
# aired = aired_from / aired_to

objects = AnimeManager()

Expand Down
6 changes: 4 additions & 2 deletions apps/animes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class Meta:
"media_type",
"episodes",
"status",
"release",
"aired_from",
"aired_to",
"studio_id",
"source",
"genres",
Expand Down Expand Up @@ -71,7 +72,8 @@ class Meta:
"media_type",
"episodes",
"status",
"release",
"aired_from",
"aired_to",
"studio_id",
"source",
"genres",
Expand Down
6 changes: 3 additions & 3 deletions apps/animes/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for Models in Animes App."""

from datetime import date
# from datetime import date
from django.test import TestCase
from django.core.exceptions import ValidationError

Expand Down Expand Up @@ -29,7 +29,7 @@ def test_creation(self):
synopsis="Incapacitated...",
episodes=25,
duration="23 min. per ep.",
release=date(1997, 10, 8),
# release=date(1997, 10, 8),
media_type="tv",
website="https://www.vap.co.jp/berserk/tv.html",
trailer="https://youtu.be/5g5uPsKDGYg",
Expand All @@ -53,7 +53,7 @@ def test_creation(self):
self.assertEqual(anime.synopsis, "Incapacitated...")
self.assertEqual(anime.episodes, 25)
self.assertEqual(anime.duration, "23 min. per ep.")
self.assertEqual(anime.release, date(1997, 10, 8))
# self.assertEqual(anime.release, date(1997, 10, 8))
self.assertEqual(anime.media_type, "tv")
self.assertEqual(anime.website, "https://www.vap.co.jp/berserk/tv.html")
self.assertEqual(anime.trailer, "https://youtu.be/5g5uPsKDGYg")
Expand Down
13 changes: 11 additions & 2 deletions apps/mangas/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def get_recommendations(self):
"id",
"name",
"image",
"release",
"published_from",
"published_to",
"media_type",
"status",
)
Expand All @@ -34,7 +35,15 @@ def get_by_genre(self, genre):
return (
self.get_available()
.filter(genres=genre)
.only("id", "name", "image", "release", "media_type", "status")
.only(
"id",
"name",
"image",
"published_from",
"published_to",
"media_type",
"status",
)
)


Expand Down
7 changes: 5 additions & 2 deletions apps/mangas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ class Manga(BaseModel, SlugMixin):
choices=MediaTypeChoices.choices,
default=MediaTypeChoices.MANGA,
)
volumes = models.PositiveIntegerField(_("volumes"), default=1)
chapters = models.PositiveIntegerField(_("chapters"), default=1)
volumes = models.PositiveIntegerField(_("volumes"), default=1)
status = models.CharField(
_("status"),
max_length=10,
choices=StatusChoices.choices,
default=StatusChoices.AIRING,
)
release = models.DateField(_("release"))
published_from = models.DateField(_("published from"))
published_to = models.DateField(_("published to"), blank=True, null=True)
genres = models.ManyToManyField(Genre, verbose_name=_("genres"))
themes = models.ManyToManyField(Theme, verbose_name=_("themes"))
demographic_id = models.ForeignKey(
Expand Down Expand Up @@ -109,6 +110,8 @@ class Manga(BaseModel, SlugMixin):
members = models.PositiveIntegerField(_("members"), default=0)
favorites = models.PositiveIntegerField(_("favorites"), default=0)

# published = published_from / published_to

objects = MangaManager()

class Meta:
Expand Down
9 changes: 6 additions & 3 deletions apps/mangas/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Meta:
"volumes",
"chapters",
"status",
"release",
"published_from",
"published_to",
"genres",
"themes",
"demographic_id",
Expand Down Expand Up @@ -66,7 +67,8 @@ class Meta:
"volumes",
"chapters",
"status",
"release",
"published_from",
"published_to",
"genres",
"themes",
"demographic_id",
Expand All @@ -91,7 +93,8 @@ class Meta:
"id",
"name",
"image",
"release",
"published_from",
"published_to",
"media_type",
"status",
]
4 changes: 1 addition & 3 deletions apps/mangas/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for Models in Mangas App."""

from datetime import date
# from datetime import date
from django.test import TestCase
from django.core.exceptions import ValidationError

Expand Down Expand Up @@ -29,7 +29,6 @@ def test_manga_creation(self):
image=None,
synopsis="Denji has...",
chapters=97,
release=date(2018, 12, 3),
media_type=1,
website="https://www.shonenjump.com/j/rensai/chainsaw.html",
status=1,
Expand All @@ -49,7 +48,6 @@ def test_manga_creation(self):
self.assertEqual(manga.name_rom, "Chainsaw Man")
self.assertEqual(manga.synopsis, "Denji has...")
self.assertEqual(manga.chapters, 97)
self.assertEqual(manga.release, date(2018, 12, 3))
self.assertEqual(manga.media_type, 1)
self.assertEqual(
manga.website, "https://www.shonenjump.com/j/rensai/chainsaw.html"
Expand Down

0 comments on commit 8610ec1

Please sign in to comment.