Skip to content

Commit 90883b5

Browse files
committed
add validation in models.py
1 parent 9c24a38 commit 90883b5

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

server/game_dev/models.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.db import models
2+
from django.core.exceptions import ValidationError
23

34

45
class Member(models.Model):
@@ -66,12 +67,15 @@ class CompletionStatus(models.IntegerChoices):
6667
blank=True,
6768
help_text="If a game is playable and has a web demo stored on itch.io, please enter the embed developer ID"
6869
)
69-
7070
itchGameWidth = models.PositiveBigIntegerField(
71-
default=0
71+
default=None,
72+
null=True,
73+
blank=True,
7274
)
7375
itchGameHeight = models.PositiveBigIntegerField(
74-
default=0
76+
default=None,
77+
null=True,
78+
blank=True,
7579
)
7680

7781
thumbnail = models.ImageField(upload_to="games/", null=True)
@@ -80,6 +84,14 @@ class CompletionStatus(models.IntegerChoices):
8084
def __str__(self):
8185
return str(self.name)
8286

87+
def clean(self):
88+
super().clean()
89+
if self.itchGamePlayableID:
90+
if not self.itchGameWidth:
91+
raise ValidationError({"itchGameWidth": "Game width is required if itchGamePlayableID is set."})
92+
if not self.itchGameHeight:
93+
raise ValidationError({"itchGameHeight": "Game height is required if itchGamePlayableID is set."})
94+
8395

8496
class GameShowcase(models.Model):
8597
game = models.OneToOneField('Game', on_delete=models.CASCADE, related_name='game_showcases')

0 commit comments

Comments
 (0)