Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Javad-Ak committed Sep 21, 2024
1 parent b5facc9 commit 62ab2b6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
22 changes: 21 additions & 1 deletion core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,24 @@ class CouponAdmin(admin.ModelAdmin):
list_display = ['name', 'count', 'percentage']


admin.site.register(SingletonCompetition, SingletonModelAdmin)
@admin.register(SingletonCompetition)
class SingletonCompetitionAdmin(SingletonModelAdmin):
def remained_capacity(self, obj):
return obj.get_remain_capacity()

fields = None
fieldsets = (
('Dates', {
"fields": (
('start', 'end'),
),
}),
('Details', {
'fields': (
'title', 'capacity', 'remained_capacity', 'cost', 'is_online', 'presentation_link', 'content', 'files',
'is_registration_active'
),
'classes': ('wide', 'extrapretty'),
})
)
readonly_fields = ('remained_capacity',)
6 changes: 3 additions & 3 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from user.models import *
from user import models as user_models
from django.db import models
from rest_framework.exceptions import ValidationError
from datetime import datetime

from solo.models import SingletonModel

from GD.settings.base import AUTH_USER_MODEL, PAYWALL
from tinymce.models import HTMLField

from tinymce.models import HTMLField

IDPAY_STATUS = [
(1, 'payment_not_made'),
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_remain_capacity(self):

def registered(self):
count = 0
for team in Team.objects.all():
for team in user_models.Team.objects.all():
if team.get_payment_state() == "COMPLETED":
count += team.members.count()

Expand Down
6 changes: 3 additions & 3 deletions user/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from core.models import *
from core import models as core_models
from django.db import models

from django.core.validators import RegexValidator
Expand Down Expand Up @@ -52,9 +52,9 @@ class Team(models.Model):

def get_payment_state(self):
for member in self.members.all():
args = {'user': member, 'competition': SingletonCompetition.get_solo(),
args = {'user': member, 'competition': core_models.SingletonCompetition.get_solo(),
'service_type': 'CP', 'payment_state': 'CM'}
query = EventService.objects.filter(**args)
query = core_models.EventService.objects.filter(**args)
if query.exists():
return "COMPLETED"
else:
Expand Down
2 changes: 1 addition & 1 deletion user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def enroll(self, request):
message=TEAM_NOT_ACCEPTED,
status_code=status.HTTP_406_NOT_ACCEPTABLE,
)
if competition.get_remain_capacity() < team.members.count:
if competition.get_remain_capacity() < team.members.count():
return self.set_response(
error=f"this {model_name} is full",
status=406,
Expand Down

0 comments on commit 62ab2b6

Please sign in to comment.