Last active
February 16, 2024 19:42
-
-
Save rg3915/ab00a3789d0582c8d88cd850a05a18a6 to your computer and use it in GitHub Desktop.
Retorna Estado choices Django Ninja API
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 ninja import Router, Schema | |
router = Router() | |
STATE_CHOICES = ( | |
('AC', 'Acre'), | |
('AL', 'Alagoas'), | |
('AP', 'Amapá'), | |
('AM', 'Amazonas'), | |
('BA', 'Bahia'), | |
('CE', 'Ceará'), | |
('DF', 'Distrito Federal'), | |
('ES', 'Espírito Santo'), | |
('GO', 'Goiás'), | |
('MA', 'Maranhão'), | |
('MT', 'Mato Grosso'), | |
('MS', 'Mato Grosso do Sul'), | |
('MG', 'Minas Gerais'), | |
('PA', 'Pará'), | |
('PB', 'Paraíba'), | |
('PR', 'Paraná'), | |
('PE', 'Pernambuco'), | |
('PI', 'Piauí'), | |
('RJ', 'Rio de Janeiro'), | |
('RN', 'Rio Grande do Norte'), | |
('RS', 'Rio Grande do Sul'), | |
('RO', 'Rondônia'), | |
('RR', 'Roraima'), | |
('SC', 'Santa Catarina'), | |
('SP', 'São Paulo'), | |
('SE', 'Sergipe'), | |
('TO', 'Tocantins') | |
) | |
class StateSchema(Schema): | |
titulo: str | |
uf: str | |
@router.get('states', response=list[StateSchema]) | |
def list_states(request): | |
return [{'titulo': item[1], 'uf': item[0]} for item in STATE_CHOICES] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment