Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions projects/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.contrib import admin

from projects.models import (
DefaultProjectCover,
Project,
Achievement,
Collaborator,
DefaultProjectCover,
Project,
ProjectLink,
ProjectNews,
)
Expand All @@ -17,11 +17,79 @@ class ProjectAdmin(admin.ModelAdmin):
"name",
"draft",
"is_company",
"track",
"direction",
"specialty",
)
list_display_links = (
"id",
"name",
)
search_fields = (
"name",
"track",
"specialty",
)
list_filter = (
"draft",
"is_company",
"track",
"direction",
"specialty",
)

fieldsets = (
(
"Основная информация",
{
"fields": (
"name",
"description",
"leader",
"industry",
"region",
"step",
"draft",
"is_company",
)
},
),
(
"Для проектов ПД МосПолитеха",
{
"fields": (
"track",
"direction",
"specialty",
"actuality",
"goal",
"problem",
)
},
),
(
"Медиа и обложка",
{
"fields": (
"presentation_address",
"image_address",
"cover",
"cover_image_address",
)
},
),
(
"Служебные поля",
{
"fields": (
"hidden_score",
"datetime_created",
"datetime_updated",
)
},
),
)
readonly_fields = ("datetime_created", "datetime_updated")


@admin.register(ProjectNews)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Generated by Django 4.2.11 on 2025-07-03 08:53

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("projects", "0023_project_cover_image_address"),
]

operations = [
migrations.AddField(
model_name="project",
name="actuality",
field=models.TextField(
blank=True,
help_text="Почему проект важен (до 1000\u202fсимв.)",
null=True,
validators=[django.core.validators.MaxLengthValidator(1000)],
verbose_name="Актуальность",
),
),
migrations.AddField(
model_name="project",
name="direction",
field=models.CharField(
blank=True,
help_text="Более общее направление деятельности проекта",
max_length=256,
null=True,
verbose_name="Направление",
),
),
migrations.AddField(
model_name="project",
name="goal",
field=models.CharField(
blank=True,
help_text="Главная цель проекта (до 500\u202fсимв.)",
max_length=500,
null=True,
verbose_name="Цель",
),
),
migrations.AddField(
model_name="project",
name="problem",
field=models.TextField(
blank=True,
help_text="Какую проблему решает проект (до 1000\u202fсимв.)",
null=True,
validators=[django.core.validators.MaxLengthValidator(1000)],
verbose_name="Проблема",
),
),
migrations.AddField(
model_name="project",
name="specialty",
field=models.CharField(
blank=True,
help_text="Специализация проекта",
max_length=256,
null=True,
verbose_name="Специальность",
),
),
migrations.AddField(
model_name="project",
name="track",
field=models.CharField(
blank=True,
help_text="Направление/курс, в рамках которого реализуется проект",
max_length=256,
null=True,
verbose_name="Трек",
),
),
]
55 changes: 52 additions & 3 deletions projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from django.contrib.auth import get_user_model
from django.contrib.contenttypes.fields import GenericRelation
from django.core.validators import MaxLengthValidator
from django.db import models
from django.db.models import UniqueConstraint

from core.models import Like, View
from files.models import UserFile
from industries.models import Industry

from projects.constants import VERBOSE_STEPS
from projects.managers import AchievementManager, CollaboratorManager, ProjectManager
from users.models import CustomUser
Expand Down Expand Up @@ -53,7 +53,11 @@ def get_random_file(cls):
@classmethod
def get_random_file_link(cls):
# FIXME: this is not efficient, but for ~10 default covers it should be ok
return cls.objects.order_by("?").first().image.link if cls.objects.order_by("?").first().image else None
return (
cls.objects.order_by("?").first().image.link
if cls.objects.order_by("?").first().image
else None
)

class Meta:
verbose_name = "Обложка проекта"
Expand Down Expand Up @@ -85,9 +89,54 @@ class Project(models.Model):
name = models.CharField(max_length=256, null=True, blank=True)
description = models.TextField(null=True, blank=True)
region = models.CharField(max_length=256, null=True, blank=True)
step = models.PositiveSmallIntegerField(choices=VERBOSE_STEPS, null=True, blank=True)
step = models.PositiveSmallIntegerField(
choices=VERBOSE_STEPS, null=True, blank=True
)
hidden_score = models.PositiveSmallIntegerField(default=100)

track = models.CharField(
max_length=256,
blank=True,
null=True,
verbose_name="Трек",
help_text="Направление/курс, в рамках которого реализуется проект",
)
direction = models.CharField(
max_length=256,
blank=True,
null=True,
verbose_name="Направление",
help_text="Более общее направление деятельности проекта",
)
specialty = models.CharField(
max_length=256,
blank=True,
null=True,
verbose_name="Специальность",
help_text="Специализация проекта",
)
actuality = models.TextField(
blank=True,
null=True,
validators=[MaxLengthValidator(1000)],
verbose_name="Актуальность",
help_text="Почему проект важен (до 1000 симв.)",
)
goal = models.CharField(
max_length=500,
blank=True,
null=True,
verbose_name="Цель",
help_text="Главная цель проекта (до 500 симв.)",
)
problem = models.TextField(
blank=True,
null=True,
validators=[MaxLengthValidator(1000)],
verbose_name="Проблема",
help_text="Какую проблему решает проект (до 1000 симв.)",
)

industry = models.ForeignKey(
Industry,
on_delete=models.SET_NULL,
Expand Down
14 changes: 10 additions & 4 deletions projects/serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from django.contrib.auth import get_user_model
from rest_framework import serializers
from django.core.cache import cache
from rest_framework import serializers

from core.serializers import SkillToObjectSerializer
from core.services import get_views_count, get_likes_count, is_fan
from core.services import get_likes_count, get_views_count, is_fan
from core.utils import get_user_online_cache_key
from files.serializers import UserFileSerializer
from industries.models import Industry
from projects.models import Project, Achievement, Collaborator, ProjectNews
from projects.models import Achievement, Collaborator, Project, ProjectNews
from projects.validators import validate_project
from vacancy.serializers import ProjectVacancyListSerializer

Expand Down Expand Up @@ -64,7 +65,6 @@ class Meta:


class ProjectDetailSerializer(serializers.ModelSerializer):

achievements = AchievementListSerializer(many=True, read_only=True)
cover = UserFileSerializer(required=False)
collaborators = CollaboratorSerializer(
Expand Down Expand Up @@ -130,6 +130,12 @@ class Meta:
"cover",
"cover_image_address",
"partner_programs_tags",
"track",
"direction",
"specialty",
"actuality",
"goal",
"problem",
]
read_only_fields = [
"leader",
Expand Down