Skip to content

Commit

Permalink
Merge pull request #165 from pythonkr/feature/sponsor-admin
Browse files Browse the repository at this point in the history
후원사 상세 페이지를 위한 API 구현
  • Loading branch information
jungmir authored Sep 18, 2024
2 parents f07cc58 + 8901ecb commit cc8c4e2
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 8 deletions.
32 changes: 29 additions & 3 deletions sponsor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django_summernote.admin import SummernoteModelAdmin
from import_export.admin import ImportExportModelAdmin

from sponsor.models import Sponsor, SponsorLevel, Patron
from sponsor.models import Sponsor, SponsorLevel, Patron, SponsorBenefit, BenefitByLevel


class SponsorAdmin(SummernoteModelAdmin):
Expand All @@ -21,7 +21,7 @@ class SponsorAdmin(SummernoteModelAdmin):
"accepted",
"paid_at",
)
list_filter = ("accepted",)
list_filter = ("accepted", "submitted")
ordering = ("-created_at",)


Expand All @@ -35,15 +35,41 @@ class SponsorLevelAdmin(SummernoteModelAdmin):
"name",
"price",
"limit",
"year",
)
list_editable = ("order",)
ordering = ("order",)
search_fields = ("name",)
search_fields = ("name", "year")


admin.site.register(SponsorLevel, SponsorLevelAdmin)


class SponsorBenefitAdmin(SummernoteModelAdmin):
list_display = (
"id",
"name",
"desc",
"unit",
"year",
"is_countable",
)
ordering = ("-year", "id")
search_fields = ("name", "year")
list_editable = ("unit", "is_countable")


admin.site.register(SponsorBenefit, SponsorBenefitAdmin)


class BenefitByLevelAdmin(SummernoteModelAdmin):
list_display = ("id", "benefit", "level", "offer", "uncountable_offer")
list_editable = ("offer",)


admin.site.register(BenefitByLevel, BenefitByLevelAdmin)


class PatronAdmin(SummernoteModelAdmin, ImportExportModelAdmin):
list_display = (
"id",
Expand Down
46 changes: 46 additions & 0 deletions sponsor/migrations/0010_alter_benefitbylevel_options_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 4.1.5 on 2024-09-18 03:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sponsor", "0009_sponsorbenefit_year_sponsorlevel_benefits"),
]

operations = [
migrations.AlterModelOptions(
name="benefitbylevel",
options={
"verbose_name": "후원사 등급별 혜택",
"verbose_name_plural": "후원사 등급별 혜택 목록",
},
),
migrations.AlterModelOptions(
name="sponsorbenefit",
options={
"verbose_name": "후원사 혜택",
"verbose_name_plural": "후원사 혜택 목록",
},
),
migrations.AddField(
model_name="benefitbylevel",
name="uncountable_offer",
field=models.TextField(blank=True, help_text="셀 수 없는 혜택", null=True),
),
migrations.AlterField(
model_name="benefitbylevel",
name="offer",
field=models.PositiveIntegerField(
help_text="제공 하는 혜택 개수", null=True
),
),
migrations.AlterField(
model_name="sponsorbenefit",
name="unit",
field=models.CharField(
blank=True, help_text="혜택 단위", max_length=10, null=True
),
),
]
20 changes: 20 additions & 0 deletions sponsor/migrations/0011_alter_benefitbylevel_offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.5 on 2024-09-18 12:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sponsor", "0010_alter_benefitbylevel_options_and_more"),
]

operations = [
migrations.AlterField(
model_name="benefitbylevel",
name="offer",
field=models.PositiveIntegerField(
blank=True, help_text="제공 하는 혜택 개수", null=True
),
),
]
21 changes: 17 additions & 4 deletions sponsor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ def get_queryset(self):

class SponsorBenefit(models.Model):
class Meta:
verbose_name = "후원사 등급 별 혜택"
verbose_name_plural = "후원사 등급 별 혜택 목록"
verbose_name = "후원사 혜택"
verbose_name_plural = "후원사 혜택 목록"

name = models.CharField(max_length=255, help_text="혜택 이름")
desc = models.TextField(null=True, blank=True, help_text="기타")
unit = models.CharField(max_length=10, help_text="혜택 단위")
unit = models.CharField(max_length=10, null=True, blank=True, help_text="혜택 단위")
year = models.IntegerField(default=2023)
is_countable = models.BooleanField(
default=True, help_text="제공 하는 혜택이 셀 수 있는지 여부"
)

def __str__(self):
return self.name


class SponsorLevel(models.Model):
class Meta:
Expand Down Expand Up @@ -75,6 +78,8 @@ def __str__(self):

class BenefitByLevel(models.Model):
class Meta:
verbose_name = "후원사 등급별 혜택"
verbose_name_plural = "후원사 등급별 혜택 목록"
constraints = [
models.UniqueConstraint(
fields=["benefit_id", "level_id"], name="IX_BENEFIT_BY_LEVEL_1"
Expand All @@ -87,7 +92,15 @@ class Meta:
level = models.ForeignKey(
SponsorLevel, on_delete=models.CASCADE, related_name="benefit_by_level"
)
offer = models.PositiveIntegerField(help_text="제공 하는 혜택 개수")
offer = models.PositiveIntegerField(
null=True, blank=True, help_text="제공 하는 혜택 개수"
)
uncountable_offer = models.TextField(
null=True, blank=True, help_text="셀 수 없는 혜택"
)

def __str__(self):
return f"{self.level!s} - {self.benefit!s}"


def registration_file_upload_to(instance, filename):
Expand Down
10 changes: 9 additions & 1 deletion sponsor/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ class SponsorBenefitWithOfferSerializer(SponsorBenefitSerializer):

class Meta:
model = BenefitByLevel
fields = ["id", "name", "desc", "unit", "is_countable", "offer"]
fields = [
"id",
"name",
"desc",
"unit",
"is_countable",
"offer",
"uncountable_offer",
]

def get_benefit_id(self, obj):
breakpoint()
Expand Down

0 comments on commit cc8c4e2

Please sign in to comment.