Skip to content

Commit

Permalink
Added fields phone, telegram, cover letter to incomes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruzal committed Nov 18, 2023
1 parent 22a7156 commit bcdf51b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 14 deletions.
14 changes: 13 additions & 1 deletion backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,16 @@ class ProjectIncomesSerializer(serializers.ModelSerializer):

class Meta:
model = ProjectIncomes
fields = ('id', 'project', 'volunteer', 'status_incomes', 'created_at')
fields = (
'id',
'project',
'volunteer',
'status_incomes',
'phone',
'telegram',
'cover_letter',
'created_at',
)
read_only_fields = ('id', 'created_at')

def create(self, validated_data):
Expand All @@ -597,6 +606,9 @@ def create(self, validated_data):
project=project,
volunteer=volunteer,
status_incomes=status_incomes,
phone=validated_data.get('phone', ''),
telegram=validated_data.get('telegram', ''),
cover_letter=validated_data.get('cover_letter', ''),
)
return project_income

Expand Down
22 changes: 18 additions & 4 deletions backend/projects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,26 @@ def get_participants_display(self, obj):
[volunteer.user.last_name for volunteer in obj.participants.all()]
)

@action(label='Одобрить', description='Отправить проект на публикацию',)
@action(
label='Одобрить',
description='Отправить проект на публикацию',
)
def approve_project(self, request, obj):
obj.status_approve = Project.APPROVED
obj.save()

@action(label='Отклонить', description='Отправить проект на доработку',)
@action(
label='Отклонить',
description='Отправить проект на доработку',
)
def reject_project(self, request, obj):
obj.status_approve = Project.REJECTED
obj.save()

change_actions = ('approve_project', 'reject_project',)
change_actions = (
'approve_project',
'reject_project',
)

@action(
description='Отправить проект на публикацию',
Expand All @@ -165,7 +174,10 @@ def approve_projects(self, request, queryset):
def reject_projects(self, request, queryset):
queryset.update(status_approve=Project.REJECTED)

actions = ('approve_projects', 'reject_projects',)
actions = (
'approve_projects',
'reject_projects',
)


@register(ProjectParticipants)
Expand All @@ -189,6 +201,8 @@ class ProjectIncomesAdmin(ModelAdmin):
'project',
'volunteer',
'status_incomes',
'phone',
'telegram',
'cover_letter',
'created_at',
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.6 on 2023-11-18 22:24

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


class Migration(migrations.Migration):

dependencies = [
('projects', '0002_project_admin_comments_alter_project_name_and_more'),
]

operations = [
migrations.AddField(
model_name='projectincomes',
name='phone',
field=models.CharField(blank=True, max_length=12, validators=[projects.validators.validate_phone_number], verbose_name='Телефон'),
),
migrations.AddField(
model_name='projectincomes',
name='telegram',
field=models.CharField(blank=True, max_length=32, validators=[projects.validators.validate_telegram], verbose_name='Телеграм'),
),
]
30 changes: 21 additions & 9 deletions backend/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class Project(models.Model):
max_length=settings.MAX_LEN_NAME_PROJECT,
validators=[validate_name],
verbose_name='Название',
unique=True
unique=True,
)
description = models.TextField(
blank=True, # добавила
Expand All @@ -254,27 +254,27 @@ class Project(models.Model):
verbose_name='Картинка',
)
start_datetime = models.DateTimeField(
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
null=True,
verbose_name='Дата и время, начало мероприятия',
)
end_datetime = models.DateTimeField(
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
null=True,
verbose_name='Дата и время, окончания мероприятия',
)
start_date_application = models.DateTimeField(
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
null=True,
verbose_name='Дата и время, начало подачи заявок',
)
end_date_application = models.DateTimeField(
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
null=True,
verbose_name='Дата и время, окончания подачи заявок',
)
event_purpose = models.TextField(
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
validators=[
regex_string_validator,
LengthValidator(
Expand All @@ -286,13 +286,13 @@ class Project(models.Model):
)
event_address = models.ForeignKey(
Address,
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
null=True, # добавила
on_delete=models.CASCADE,
verbose_name='Адрес проведения проекта',
)
project_tasks = models.TextField(
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
validators=[
regex_string_validator,
LengthValidator(
Expand All @@ -303,7 +303,7 @@ class Project(models.Model):
verbose_name='Задачи проекта',
)
project_events = models.TextField(
blank=True, # добавилено для черновика
blank=True, # добавилено для черновика
validators=[
regex_string_validator,
LengthValidator(
Expand Down Expand Up @@ -493,6 +493,18 @@ class ProjectIncomes(models.Model):
default=APPLICATION_SUBMITTED,
verbose_name='Статус заявки волонтера',
)
phone = models.CharField(
validators=[validate_phone_number],
max_length=settings.LEN_PHONE,
blank=True,
verbose_name='Телефон',
)
telegram = models.CharField(
max_length=settings.MAX_LEN_TELEGRAM,
blank=True,
validators=[validate_telegram],
verbose_name='Телеграм',
)
cover_letter = models.TextField(
verbose_name='Сопроводительное письмо',
blank=True,
Expand Down

0 comments on commit bcdf51b

Please sign in to comment.