diff --git a/apps/games/admin.py b/apps/games/admin.py index 8f7adac..588f9fd 100644 --- a/apps/games/admin.py +++ b/apps/games/admin.py @@ -8,13 +8,14 @@ from .models import Game, Screenshot class GameAdmin(admin.ModelAdmin): list_display = ( "title", + "author_name", "version", "status", "created_by", "updated_at", ) list_filter = ("status", "unity_version") - search_fields = ("title", "created_by__username") + search_fields = ("title", "author_name", "created_by__username") ordering = ("-updated_at",) diff --git a/apps/games/migrations/0003_game_author_name.py b/apps/games/migrations/0003_game_author_name.py new file mode 100644 index 0000000..4d030a7 --- /dev/null +++ b/apps/games/migrations/0003_game_author_name.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.17 on 2026-10-28 09:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('games', '0002_alter_game_options_alter_screenshot_options_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='game', + name='author_name', + field=models.CharField(blank=True, default='', max_length=200, verbose_name='Автор / команда'), + ), + ] diff --git a/apps/games/models.py b/apps/games/models.py index 21e56b2..6ce7261 100644 --- a/apps/games/models.py +++ b/apps/games/models.py @@ -8,6 +8,12 @@ class Game(models.Model): max_length=200, verbose_name="Название", ) + author_name = models.CharField( + max_length=200, + blank=True, + default="", + verbose_name="Автор / команда", + ) short_description = models.CharField( max_length=300, verbose_name="Краткое описание", @@ -82,6 +88,12 @@ class Game(models.Model): verbose_name="Количество скачиваний", ) + def save(self, *args, **kwargs): + if self.file: + self.file_size = self.file.size + + super().save(*args, **kwargs) + class Meta: verbose_name = "Unity-приложение" verbose_name_plural = "Unity-приложения" diff --git a/apps/games/templates/games/game_detail.html b/apps/games/templates/games/game_detail.html new file mode 100644 index 0000000..49728af --- /dev/null +++ b/apps/games/templates/games/game_detail.html @@ -0,0 +1,115 @@ + +{% extends "games/base.html" %} + +{% block title %}{{ game.title }} — SKB Market{% endblock %} + +{% block content %} +
+ + ← Назад к каталогу + + +
+
+
+
+ {% if game.icon %} + Иконка {{ game.title }} + {% else %} +
+ Нет иконки +
+ {% endif %} +
+ +
+

{{ game.title }}

+ + {% if game.author_name %} +

+ Автор / команда: {{ game.author_name }} +

+ {% endif %} + + {% if game.short_description %} +

{{ game.short_description }}

+ {% endif %} + +
+ + Версия {{ game.version }} + + + {% if game.unity_version %} + + Unity {{ game.unity_version }} + + {% endif %} +
+ +

+ Обновлено: {{ game.updated_at|date:"d.m.Y H:i" }} +

+ +

+ Скачиваний: {{ game.download_count }} +

+
+
+ +
+ +

Об приложении

+
{{ game.description|linebreaks }}
+ + + {% with screenshots=game.screenshots.all %} + {% if screenshots %} +
+

Скриншоты

+ +
+ + {% for screenshot in screenshots %} +
+ + Скриншот {{ game.title }} + +
+ {% endfor %} +
+ {% endif %} + {% endwith %} + +

Файл приложения

+

+ Размер: + {% if game.file_size %} + {{ game.file_size|filesizeformat }} + {% else %} + Пока не определён + {% endif %} +

+ + {% if game.file %} + + Скачать приложение + + {% else %} +

Файл пока не загружен.

+ {% endif %} +
+
+
+{% endblock %} diff --git a/apps/games/templates/games/game_list.html b/apps/games/templates/games/game_list.html index f087681..4e31262 100644 --- a/apps/games/templates/games/game_list.html +++ b/apps/games/templates/games/game_list.html @@ -38,7 +38,6 @@ {% endif %}
{{ game.title }}
- {{ game.size_mb }} МБ

{{ game.short_description }}

diff --git a/apps/games/urls.py b/apps/games/urls.py index 561bfc5..da7e6ab 100644 --- a/apps/games/urls.py +++ b/apps/games/urls.py @@ -10,4 +10,9 @@ urlpatterns = [ views.GameDetailView.as_view(), name="game_detail", ), + path( + "game//download/", + views.download_game, + name="game_download", + ), ] \ No newline at end of file diff --git a/apps/games/views.py b/apps/games/views.py index ea09612..da3a10b 100644 --- a/apps/games/views.py +++ b/apps/games/views.py @@ -1,5 +1,9 @@ from django.views.generic import ListView, DetailView +from django.db.models import F +from django.http import FileResponse, Http404 +from django.shortcuts import get_object_or_404 + from .models import Game @@ -29,4 +33,27 @@ class GameDetailView(DetailView): context_object_name = "game" def get_queryset(self): - return Game.objects.filter(status=Game.STATUS_PUBLISHED) \ No newline at end of file + return Game.objects.filter(status=Game.STATUS_PUBLISHED) + + +def download_game(request, pk): + game = get_object_or_404( + Game, + pk=pk, + status=Game.STATUS_PUBLISHED, + ) + + if not game.file: + raise Http404("Файл приложения не найден") + + response = FileResponse( + game.file.open("rb"), + as_attachment=True, + filename=game.file.name.split("/")[-1], + ) + + Game.objects.filter(pk=game.pk).update( + download_count=F("download_count") + 1 + ) + + return response