Skip to content

Instantly share code, notes, and snippets.

@CleitonDeLima
Last active May 8, 2017 17:39
Show Gist options
  • Save CleitonDeLima/1250a42adc3561981e1377c2f7636210 to your computer and use it in GitHub Desktop.
Save CleitonDeLima/1250a42adc3561981e1377c2f7636210 to your computer and use it in GitHub Desktop.
# models.py
class State(models.Model):
name = models.CharField(_('nome'), max_length=60)
class Meta:
verbose_name = _('estado')
verbose_name_plural = _('estados')
def __str__(self):
return self.name
class City(models.Model):
name = models.CharField(_('nome'), max_length=60)
state = models.ForeignKey('regions.State', verbose_name=_('estado'), related_name='cities')
class Meta:
verbose_name = _('cidade')
verbose_name_plural = _('cidades')
def __str__(self):
return self.name + ' ' + self.state.name
# forms.py
class IssuerForm(forms.ModelForm):
class Meta:
model = Issuer
fields = [
'name',
'cnpj',
'city' # fk para City
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment