models.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import logging
  2. from typing import Dict
  3. from uuid import uuid4
  4. from django.conf import settings
  5. from django.db import models
  6. from django.urls import reverse
  7. from django_extensions.db.models import TimeStampedModel
  8. from scrobbles.mixins import ScrobblableMixin
  9. logger = logging.getLogger(__name__)
  10. BNULL = {"blank": True, "null": True}
  11. class VideoGameCollection(TimeStampedModel):
  12. name = models.CharField(max_length=255)
  13. uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
  14. cover = models.ImageField(upload_to="games/series-covers/", **BNULL)
  15. igdb_id = models.IntegerField(**BNULL)
  16. def __str__(self):
  17. return self.name
  18. def get_absolute_url(self):
  19. return reverse(
  20. "videogames:videogamecollection_detail", kwargs={"slug": self.uuid}
  21. )
  22. class VideoGame(ScrobblableMixin):
  23. COMPLETION_PERCENT = getattr(settings, "GAME_COMPLETION_PERCENT", 100)
  24. title = models.CharField(max_length=255)
  25. igdb_id = models.IntegerField(**BNULL)
  26. alternative_name = models.CharField(max_length=255)
  27. uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
  28. cover = models.ImageField(upload_to="games/covers/", **BNULL)
  29. screenshot = models.ImageField(upload_to="games/covers/", **BNULL)
  30. rating = models.FloatField(**BNULL)
  31. rating_count = models.IntegerField(**BNULL)
  32. release_date = models.DateTimeField(**BNULL)
  33. def __str__(self):
  34. return self.title
  35. def get_absolute_url(self):
  36. return reverse(
  37. "videogames:videogame_detail", kwargs={"slug": self.uuid}
  38. )
  39. @classmethod
  40. def find_or_create(cls, data_dict: Dict) -> "VideoGame":
  41. ...