Skip to content

Commit

Permalink
change question type display in admin (#260)
Browse files Browse the repository at this point in the history
* change question type display in admin

* some fix

---------

Co-authored-by: Konstantin Raikhert <raikhert13@gmail.com>
  • Loading branch information
alekseikoznov and KonstantinRaikhert authored Sep 1, 2023
1 parent df7b67f commit 7cfae55
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 23 deletions.
19 changes: 2 additions & 17 deletions src/bot/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class QuestionAdmin(RegionForAdmin):
form = QuestionAdminForm
list_display = (
"get_question",
"get_short_description",
"get_question_type",
"short_description",
"question_type",
"get_answer",
"get_regions",
)
Expand All @@ -41,16 +41,6 @@ def get_question(self, obj):
"""Display questions in admin panel."""
return obj.question[:100]

@admin.display(description="Короткое описание")
def get_short_description(self, obj):
"""Display short_descriptions in admin panel."""
return obj.short_description[:100]

@admin.display(description="Тип вопроса")
def get_question_type(self, obj):
"""Display question_type in admin panel."""
return obj.question_type[:100]

@admin.display(description="Ответ")
def get_answer(self, obj):
"""Display answer in admin panel."""
Expand Down Expand Up @@ -95,11 +85,6 @@ def get_title(self, obj):
"""Display title in admin panel."""
return obj.title[:100]

@admin.display(description="Короткое описание")
def get_short_description(self, obj):
"""Display short_description in admin panel."""
return obj.short_description[:100]

@admin.display(description="Описание программы")
def get_fund_text(self, obj):
"""Display fund_text in admin panel."""
Expand Down
3 changes: 1 addition & 2 deletions src/bot/handlers/assistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
)
from bot.keyboards.assistance_types import assistance_types_keyboard_markup
from bot.keyboards.utils.callback_data_parse import parse_callback_data
from bot.models import HelpTypes
from bot_settings.models import BotSettings

DEFAULT_PAGE = 1
Expand Down Expand Up @@ -139,7 +138,7 @@ async def contact_with_us(
) -> States:
"""Ask question and show contacts."""
query = update.callback_query
context.user_data[States.QUESTION_TYPE] = HelpTypes.COMMON_QUESTION.value
context.user_data[States.QUESTION_TYPE] = "COMMON_QUESTION"
await query.answer()
await query.edit_message_text(
text=CONTACT_SHOW_MESSAGE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 4.2.4 on 2023-09-01 10:51

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("bot", "0005_alter_coordinator_email_address_and_more"),
]

operations = [
migrations.AlterField(
model_name="fundprogram",
name="short_description",
field=models.CharField(
help_text="Введите название кнопки в боте для данной программы",
max_length=20,
verbose_name="Текст на кнопке",
),
),
migrations.AlterField(
model_name="question",
name="question_type",
field=models.CharField(
choices=[
("LEGAL_ASSISTANCE", "Юридическая помощь"),
("SOCIAL_ASSISTANCE", "Социальная помощь"),
("PSYCHOLOGICAL_ASSISTANCE", "Психологическая помощь"),
],
default="LEGAL_ASSISTANCE",
help_text="Выберите тип помощи для вопроса",
max_length=100,
verbose_name="Тип вопроса",
),
),
]
23 changes: 23 additions & 0 deletions src/bot/migrations/0007_alter_question_short_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.4 on 2023-09-01 15:43

from django.db import migrations, models


class Migration(migrations.Migration):
"""Migrations for bot."""

dependencies = [
("bot", "0006_alter_fundprogram_short_description_and_more"),
]

operations = [
migrations.AlterField(
model_name="question",
name="short_description",
field=models.CharField(
help_text="Введите название кнопки в боте для данного вопроса",
max_length=20,
verbose_name="Текст на кнопке",
),
),
]
5 changes: 2 additions & 3 deletions src/bot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class HelpTypes(models.TextChoices):
PSYCHOLOGICAL_ASSISTANCE = "PSYCHOLOGICAL_ASSISTANCE", _(
"Психологическая помощь"
)
COMMON_QUESTION = "COMMON_QUESTION", _("Общий вопрос")


class Question(BaseModel):
Expand All @@ -118,7 +117,7 @@ class Question(BaseModel):
)
short_description = models.CharField(
max_length=20,
verbose_name="Короткое описание",
verbose_name="Текст на кнопке",
help_text="Введите название кнопки в боте для данного вопроса",
)
regions = models.ManyToManyField(
Expand Down Expand Up @@ -161,7 +160,7 @@ class FundProgram(BaseModel):
)
short_description = models.CharField(
max_length=20,
verbose_name="Короткое описание",
verbose_name="Текст на кнопке",
help_text="Введите название кнопки в боте для данной программы",
)
regions = models.ManyToManyField(
Expand Down
7 changes: 6 additions & 1 deletion src/bot_settings/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class BotSettingsAdmin(admin.ModelAdmin):
"""Base admin configuration for BotSettings model."""

list_display = ("get_title", "type", "get_value")
list_display = ("get_title", "get_type", "get_value")
list_filter = ("type",)
search_fields = ("title", "type", "value")
readonly_fields = ("type",)
Expand All @@ -22,6 +22,11 @@ def get_title(self, obj):
"""Display title of settings in admin panel."""
return obj.title[:100]

@admin.display(description="Тип значения")
def get_type(self, obj):
"""Display type of settings in admin panel."""
return obj.get_type_display()[:100]

@admin.display(description="Значение настройки")
def get_value(self, obj):
"""Display value of settings in admin panel."""
Expand Down

0 comments on commit 7cfae55

Please sign in to comment.