Skip to content

Commit

Permalink
Merge pull request #168 from pythonkr/devdev
Browse files Browse the repository at this point in the history
스폰서 API 프로덕션에 반영
  • Loading branch information
jungmir authored Sep 21, 2024
2 parents f07cc58 + b6c38e2 commit 94b4b89
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 17 deletions.
1 change: 1 addition & 0 deletions requirements-local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ drf-spectacular==0.27.2
django-cors-headers==3.14.0
requests==2.28.2
django-picklefield==3.1
setuptools==74.1.2
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Markdown==3.4.1
mysql-connector-python==8.0.32
mysqlclient==2.2.4
sqlparse==0.4.3
setuptools==74.1.2
tzdata==2022.7
sorl-thumbnail==12.9.0
django-summernote==0.8.20.0
Expand Down
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
),
),
]
29 changes: 18 additions & 11 deletions sponsor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@
User = get_user_model()


class SponsorLevelManager(models.Manager):
def get_queryset(self):
return super(SponsorLevelManager, self).get_queryset().all().order_by("order")


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:
verbose_name = "후원사 등급"
verbose_name_plural = "후원사 등급"
ordering = ["order"]

name = models.CharField(
max_length=255, blank=True, default="", help_text="후원 등급명"
Expand All @@ -49,8 +48,6 @@ class Meta:
SponsorBenefit, through="BenefitByLevel", related_name="level"
)

objects = SponsorLevelManager()

@property
def current_remaining_number(self):
return (
Expand All @@ -75,6 +72,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 +86,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
4 changes: 2 additions & 2 deletions sponsor/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SponsorLevelViewSet(ModelViewSet):
http_method_names = ["get", "post", "put", "delete"]

def get_queryset(self):
return SponsorLevel.objects.get_queryset()
return SponsorLevel.objects.filter(year=self.request.version).all()

def get_serializer_class(self):
match self.action:
Expand Down Expand Up @@ -159,7 +159,7 @@ class SponsorRemainingAccountViewSet(ModelViewSet):
http_method_names = ["get"]

def get_queryset(self):
return SponsorLevel.objects.all()
return SponsorLevel.objects.filter(year=self.request.version).all()

def list(self, request, *args, **kwargs):
queryset = SponsorLevel.objects.all().order_by("-price")
Expand Down

0 comments on commit 94b4b89

Please sign in to comment.