-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
36 lines (25 loc) · 935 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django.db import models
from django.core.exceptions import ValidationError
# Create your models here.
class Pokemon(models.Model):
dex_id = models.IntegerField(unique=True)
name = models.CharField(max_length=32)
weight = models.IntegerField()
height = models.IntegerField()
def __str__(self):
return f'{self.name}'
class Meta:
verbose_name = 'Pokemon'
verbose_name_plural = 'Pokemons'
class Team(models.Model):
owner = models.CharField(max_length=32)
pokemons = models.ManyToManyField(Pokemon)
def validate_max_pokemons(self):
max_pokemons = 6
if self.outros_modelos.count() > max_pokemons:
raise ValidationError(f"Só é permitido um máximo de {max_pokemons} pokemons por time.")
def __str__(self):
return f'Time de {self.owner}'
class Meta:
verbose_name = 'Team'
verbose_name_plural = 'Teams'