From 5d5356fb59dcb9d2d31d37ca84f64949a8f69e06 Mon Sep 17 00:00:00 2001 From: Guilherme Gondim Date: Thu, 21 Aug 2008 19:27:08 +0000 Subject: [PATCH] =?UTF-8?q?Adicionado=20suporte=20=C3=A0=20documenta=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20admin.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/casas/admin.py | 28 +++++++++++++++++++++++++++- sigi/apps/casas/models.py | 22 +++++++++++++++++++--- sigi/apps/contatos/models.py | 8 +++++++- sigi/settings.py | 1 + sigi/urls.py | 2 +- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/sigi/apps/casas/admin.py b/sigi/apps/casas/admin.py index 4638633..8470e05 100644 --- a/sigi/apps/casas/admin.py +++ b/sigi/apps/casas/admin.py @@ -1,11 +1,37 @@ # -*- coding: utf-8 -*- from django.contrib import admin +from django.contrib.admin.filterspecs import ChoicesFilterSpec, FilterSpec +from django.contrib.contenttypes import generic from sigi.apps.casas.forms import CasaLegislativaForm from sigi.apps.casas.models import CasaLegislativa +from sigi.apps.contatos.models import Contato +from sigi.apps.contatos.models import Telefone + +class ContatosInline(generic.GenericTabularInline): + model = Contato + +class TelefonesInline(generic.GenericTabularInline): + model = Telefone class CasaLegislativaAdmin(admin.ModelAdmin): form = CasaLegislativaForm - list_display = ('nome', 'email', 'pagina_web') + inlines = (TelefonesInline, ContatosInline) + list_display = ('nome', 'email', 'pagina_web', 'municipio', 'uf') list_display_links = ('nome',) + list_filter = ('tipo',) + fieldsets = ( + (None, { + 'fields': ('nome', 'sigla', 'tipo', 'cnpj'), + }), + ('Endereço', { + 'fields': ('logradouro', 'bairro', 'municipio', 'cep'), + }), + ('Outras informações', { + 'fields': ('email', 'pagina_web', 'foto', 'historico'), + }), + ) + search_fields = ('nome', 'sigla', 'cnpj', 'logradouro', 'bairro', + 'cep', 'municipio__nome', 'municipio__uf__nome', + 'pagina_web') admin.site.register(CasaLegislativa, CasaLegislativaAdmin) diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index 7190b02..16f8e4d 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -10,8 +10,16 @@ class CasaLegislativa(models.Model): ('CT', 'Câmara Distrital'), ('SF', 'Senado Federal'), ) - nome = models.CharField(max_length=60) - sigla = models.CharField(max_length=30, blank=True) + nome = models.CharField( + max_length=60, + help_text='Exemplo: Câmara Municipal de Pains.' + ) + sigla = models.CharField( + max_length=30, + help_text='Forneça apenas se a Casa Legislativa indicar um. ' + 'Exemplo: cmpains.', + blank=True + ) tipo = models.CharField(max_length=2, choices=CASA_CHOICES) cnpj = models.CharField('CNPJ', max_length=18) @@ -26,7 +34,11 @@ class CasaLegislativa(models.Model): ) cep = models.CharField(max_length=9) email = models.EmailField('e-mail', blank=True) - pagina_web = models.URLField(u'página web', blank=True) + pagina_web = models.URLField( + u'página web', + help_text='Exemplo: http://www.camarapains.mg.gov.br.', + blank=True + ) telefones = generic.GenericRelation('contatos.Telefone') foto = models.ImageField( @@ -48,3 +60,7 @@ class CasaLegislativa(models.Model): def __unicode__(self): return self.nome + + def uf (self): + return self.municipio.uf.nome + uf.short_description = 'Unidade Federativa' diff --git a/sigi/apps/contatos/models.py b/sigi/apps/contatos/models.py index b717be1..589e2e8 100644 --- a/sigi/apps/contatos/models.py +++ b/sigi/apps/contatos/models.py @@ -14,10 +14,15 @@ class UnidadeFederativa(models.Model): codigo_ibge = models.PositiveIntegerField( u'código IBGE', primary_key=True, + unique=True, help_text='Código do estado segundo IBGE.' ) nome = models.CharField(max_length=25) - sigla = models.CharField(max_length=2, help_text="Exemplo: MG.") + sigla = models.CharField( + max_length=2, + unique=True, + help_text="Exemplo: MG.", + ) regiao = models.CharField(max_length=2, choices=REGIAO_CHOICES) populacao = models.PositiveIntegerField('população') @@ -33,6 +38,7 @@ class Municipio(models.Model): codigo_ibge = models.PositiveIntegerField( u'código IBGE', primary_key=True, + unique=True, help_text='Código do município segundo IBGE.' ) codigo_mesorregiao = models.PositiveIntegerField( diff --git a/sigi/settings.py b/sigi/settings.py index 84148b9..89074d6 100644 --- a/sigi/settings.py +++ b/sigi/settings.py @@ -84,6 +84,7 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'django.contrib.databrowse', 'django.contrib.admin', + 'django.contrib.admindocs', 'django_extensions', # http://django-command-extensions.googlecode.com/ 'sigi.apps.casas', 'sigi.apps.contatos', diff --git a/sigi/urls.py b/sigi/urls.py index 42dd4d8..e412cf0 100644 --- a/sigi/urls.py +++ b/sigi/urls.py @@ -10,8 +10,8 @@ map(databrowse.site.register, get_models()) urlpatterns = patterns( '', - (r'^(.*)', admin.site.root), (r'^doc/', include('django.contrib.admindocs.urls')), + (r'^(.*)', admin.site.root), # databrowse (r'^databrowse/(.*)', databrowse.site.root),