Skip to content

Commit

Permalink
feat:add new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
olees-orlenko committed Feb 12, 2024
1 parent add9961 commit 77b914b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 23 deletions.
9 changes: 2 additions & 7 deletions src/backend/apps/project/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@ class ProjectAdmin(admin.ModelAdmin):
"creator",
"started",
"ended",
"duration",
"contacts",
"level",
"busyness",
"recruitment_status",
"status",
"direction",
)
list_filter = ("level", "busyness", "status")
search_fields = ("name", "description", "purpose", "creator__username")
readonly_fields = ("duration",)
list_per_page = LIST_PER_PAGE

def duration(self, instance):
return instance.duration

duration.short_description = "Продолжительность в днях"
12 changes: 12 additions & 0 deletions src/backend/apps/project/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
BUSYNESS_CHOICES = [
(1, "10"),
(2, "20"),
(3, "30"),
(4, "40"),
]
CONTACTS_LENGTH = 256
DIRECTION_CHOICES = [
(1, "Десктоп"),
(2, "Веб"),
(3, "Мобильная"),
]
DESCRIPTION_LENGTH = 3000
LIST_PER_PAGE = 10
NAME_LENGTH = 100
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 5.0.1 on 2024-02-12 13:23

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("project", "0004_alter_project_busyness"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterModelOptions(
name="specialization",
options={
"verbose_name": "Специализация",
"verbose_name_plural": "Специализации",
},
),
migrations.RemoveField(
model_name="specialization",
name="quantity",
),
migrations.AddField(
model_name="project",
name="contacts",
field=models.TextField(
default="", max_length=256, verbose_name="Контакты для связи"
),
preserve_default=False,
),
migrations.AddField(
model_name="project",
name="direction",
field=models.IntegerField(
choices=[(1, "Десктоп"), (2, "Веб"), (3, "Мобильная")],
default=1,
verbose_name="Направление разработки",
),
preserve_default=False,
),
migrations.AddField(
model_name="project",
name="participants",
field=models.ManyToManyField(
related_name="project_participants",
to=settings.AUTH_USER_MODEL,
verbose_name="Команда проекта",
),
),
migrations.AlterField(
model_name="project",
name="busyness",
field=models.IntegerField(
choices=[(1, "10"), (2, "20"), (3, "30"), (4, "40")],
verbose_name="Занятость в часах в неделю",
),
),
]
41 changes: 25 additions & 16 deletions src/backend/apps/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

from apps.general.models import CreatedModifiedFields

from .constants import DESCRIPTION_LENGTH, NAME_LENGTH, STATUS_CHOICES
from .constants import (
BUSYNESS_CHOICES,
CONTACTS_LENGTH,
DESCRIPTION_LENGTH,
DIRECTION_CHOICES,
NAME_LENGTH,
STATUS_CHOICES,
)

User = get_user_model()

Expand All @@ -14,11 +21,10 @@ class Specialization(models.Model):
"""

name = models.CharField("Название", max_length=NAME_LENGTH)
quantity = models.PositiveSmallIntegerField()

class Meta:
verbose_name = "Специальность"
verbose_name_plural = "Специальности"
verbose_name = "Специализация"
verbose_name_plural = "Специализации"

def __str__(self) -> str:
return self.name
Expand Down Expand Up @@ -124,6 +130,7 @@ class Project(CreatedModifiedFields):
verbose_name="Навыки",
)
busyness = models.IntegerField(
choices=BUSYNESS_CHOICES,
verbose_name="Занятость в часах в неделю",
)
recruitment_status = models.IntegerField(
Expand All @@ -136,18 +143,20 @@ class Project(CreatedModifiedFields):
on_delete=models.CASCADE,
verbose_name="Статус проекта",
)

@property
def duration(self):
"""
Вычисляет и возвращает продолжительность проекта в днях.
"""
if self.ended is not None and self.started is not None:
duration = self.ended - self.started
return duration.days
return None

duration.fget.short_description = "Продолжительность"
contacts = models.TextField(
"Контакты для связи", max_length=CONTACTS_LENGTH
)
direction = models.IntegerField(
choices=DIRECTION_CHOICES,
verbose_name="Направление разработки",
# default=1,
)
participants = models.ManyToManyField(
User,
# through="Participant",
related_name="project_participants",
verbose_name="Команда проекта",
)

class Meta:
verbose_name = "Проект"
Expand Down

0 comments on commit 77b914b

Please sign in to comment.