API debugging 1 まだ問題あり

This commit is contained in:
2024-07-26 04:03:15 +00:00
parent c0fb177d02
commit 9215ba8f9f
4 changed files with 339 additions and 98 deletions

View File

@ -369,40 +369,42 @@ class Entry(models.Model):
})
# メンバーの年齢と性別をチェック
if self.team and not self.team.members.exists():
raise ValidationError({'team': 'チームにメンバーが登録されていません。'})
if self.team: # and not self.team.members.exists():
members = self.team.members.all() # membersを適切に取得
if not members.exists():
raise ValidationError({'team': 'チームにメンバーが登録されていません。'})
#members = Member.objects.filter(team=self.team)
#if not members.exists():
# # ここで、owner をMemberに登録する。 Akira 2024-7-24
# raise ValidationError("チームにメンバーが登録されていません。")
adults = [m for m in members if self.is_adult(m.user.date_of_birth)]
children = [m for m in members if self.is_child(m.user.date_of_birth)]
teenagers = [m for m in members if self.is_teenager(m.user.date_of_birth)]
if self.category.family:
if not (adults and children):
raise ValidationError("ファミリーカテゴリーには、18歳以上のメンバーと小学生以下のメンバーが各1名以上必要です。")
else:
if not adults:
raise ValidationError("18歳以上のメンバーが1名以上必要です。")
if children:
raise ValidationError("ファミリーカテゴリー以外では、小学生以下のメンバーは参加できません。")
if self.category.num_of_member == 1:
if len(members) != 1:
raise ValidationError("このカテゴリーはソロ参加のみ可能です。")
if not adults:
raise ValidationError("ソロ参加は18歳以上のみ可能です。")
if self.category.female and not members[0].user.female:
raise ValidationError("このカテゴリーは女性のみ参加可能です。")
if not self.category.female and members[0].user.female:
raise ValidationError("このカテゴリーは男性のみ参加可能です。")
if len(members) > self.category.num_of_member:
raise ValidationError(f"このカテゴリーは{self.category.num_of_member}名までの参加が必要です。")
#members = Member.objects.filter(team=self.team)
#if not members.exists():
# # ここで、owner をMemberに登録する。 Akira 2024-7-24
# raise ValidationError("チームにメンバーが登録されていません。")
adults = [m for m in members if self.is_adult(m.user.date_of_birth)]
children = [m for m in members if self.is_child(m.user.date_of_birth)]
teenagers = [m for m in members if self.is_teenager(m.user.date_of_birth)]
if self.category.family:
if not (adults and children):
raise ValidationError("ファミリーカテゴリーには、18歳以上のメンバーと小学生以下のメンバーが各1名以上必要です。")
else:
if not adults:
raise ValidationError("18歳以上のメンバーが1名以上必要です。")
if children:
raise ValidationError("ファミリーカテゴリー以外では、小学生以下のメンバーは参加できません。")
if self.category.num_of_member == 1:
if len(members) != 1:
raise ValidationError("このカテゴリーはソロ参加のみ可能です。")
if not adults:
raise ValidationError("ソロ参加は18歳以上のみ可能です。")
if self.category.female and not members[0].user.female:
raise ValidationError("このカテゴリーは女性のみ参加可能です。")
if not self.category.female and members[0].user.female:
raise ValidationError("このカテゴリーは男性のみ参加可能です。")
if len(members) > self.category.num_of_member:
raise ValidationError(f"このカテゴリーは{self.category.num_of_member}名までの参加が必要です。")
def save(self, *args, **kwargs):