Created
February 12, 2023 11:17
-
-
Save luxu/05e7c93a092fc42044dc23de02768238 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Car(models.Model): | |
AT = 'AT' | |
MA = 'MA' | |
CAMBIO = [ | |
(AT, 'Automatic'), | |
(MA, 'Manual') | |
] | |
name = models.CharField( | |
verbose_name='Nome', | |
max_length=50 | |
) | |
price = models.DecimalField( | |
'Preço', | |
decimal_places=2, | |
max_digits=5 | |
) | |
year = models.SmallIntegerField( | |
'Ano' | |
) | |
transmission = models.CharField( | |
'Transmissão', | |
max_length=2, | |
choices=CAMBIO, | |
default=MA, | |
) | |
manufacturer = models.ForeignKey( | |
'Manufacturer', | |
verbose_name='Fabricante', | |
on_delete=models.CASCADE, | |
related_name='cars' | |
) | |
def __str__(self): | |
return f'{self.name} - {self.manufacturer}' | |
class Meta: | |
verbose_name = 'Carro' | |
verbose_name_plural = 'Carros' | |
ordering = ['name'] | |
class Manufacturer(models.Model): | |
name = models.CharField( | |
'nome', | |
max_length=20 | |
) | |
def __str__(self): | |
return self.name | |
class Meta: | |
verbose_name = 'Fabricante' | |
verbose_name_plural = 'Fabricantes' | |
class City(models.Model): | |
name = models.CharField( | |
'Nome', | |
max_length=50 | |
) | |
state = models.ManyToManyField( | |
'State', | |
verbose_name='Estado' | |
) | |
def __str__(self): | |
return self.name | |
class Meta: | |
verbose_name = 'Cidade' | |
verbose_name_plural = 'Cidades' | |
class State(models.Model): | |
SP = 'sp' | |
RJ = 'rj' | |
STATE = [ | |
(SP, 'São Paulo'), | |
(RJ, 'Rio de Janeiro'), | |
] | |
name = models.CharField( | |
'Nome', | |
max_length=2, | |
choices=STATE, | |
default=SP | |
) | |
def __str__(self): | |
return self.name | |
class Meta: | |
verbose_name = 'Estado' | |
verbose_name_plural = 'Estados' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Operations to perform: | |
Synchronize unmigrated apps: debug_toolbar, django_extensions, messages, staticfiles | |
Apply all migrations: admin, auth, contenttypes, core, sessions | |
Synchronizing apps without migrations: | |
Creating tables... | |
Running deferred SQL... | |
Running migrations: | |
Applying contenttypes.0001_initial... OK | |
Applying auth.0001_initial... OK | |
Applying admin.0001_initial... OK | |
Applying admin.0002_logentry_remove_auto_add... OK | |
Applying admin.0003_logentry_add_action_flag_choices... OK | |
Applying contenttypes.0002_remove_content_type_name... OK | |
Applying auth.0002_alter_permission_name_max_length... OK | |
Applying auth.0003_alter_user_email_max_length... OK | |
Applying auth.0004_alter_user_username_opts... OK | |
Applying auth.0005_alter_user_last_login_null... OK | |
Applying auth.0006_require_contenttypes_0002... OK | |
Applying auth.0007_alter_validators_add_error_messages... OK | |
Applying auth.0008_alter_user_username_max_length... OK | |
Applying auth.0009_alter_user_last_name_max_length... OK | |
Applying auth.0010_alter_group_name_max_length... OK | |
Applying auth.0011_update_proxy_permissions... OK | |
Applying auth.0012_alter_user_first_name_max_length... OK | |
Applying core.0001_initial... OK | |
Applying core.0002_alter_car_manufacturer_alter_city_state... OK | |
Applying sessions.0001_initial... OK | |
Creating test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')... | |
FAILED [100%] | |
core\tests\test_models.py:34 (test_car) | |
'' != 'Doblô' | |
Expected :'Doblô' | |
Actual :'' | |
<Click to see difference> | |
car = <Car: - FIAT> | |
def test_car(car): | |
> assert car.name == 'Doblô' | |
E AssertionError: assert '' == 'Doblô' | |
E - Doblô | |
test_models.py:36: AssertionError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment