Found the answer here;

http://groups.google.com/group/django-users/browse_thread/thread/89b4146892801ed4/17f2d26e10709ba0?lnk=gst&q=foreignkey+list_filter#17f2d26e10709ba0

Short version: "If you only have one record in the table related to
your foreign key,
then the filter list will not show up at the side of the admin screen.
"



On Jun 8, 12:44 am, Rodrigo Cea <rodrigo...@gmail.com> wrote:
> I have a model with 4 ForeignKeys: 'autor','categoria','edicion' and
> 'dossier'. In admin.py, I am trying to assign them as "list_filter".
> However, only 2 of them actually show up within the filters, 'autor'
> and 'categoria'. All four show up as columns without any problems.
> Does anybody have any clues as to why some FKs show up as filters and
> some don't?
>
> The code:
>
> ### in models.py
>
> ### these show up
> class Autor(BaseModel):
>     """Un autor"""
>     user = models.ForeignKey(User, unique=True, blank=True, null=True)
>     nombre = models.CharField(max_length=200, help_text="""Ejemplo:
> Iván Pinto""")
>     nota = models.TextField(blank=True)
>     subeditor = models.BooleanField(default=False)
>
>     def __unicode__(self):
>         return u"%s" % self.nombre
>
>     def get_absolute_url(self):
>         return "/autor/%s/%s" % (slugify(self.nombre), self.id)
>
>     class Meta:
>         ordering = ['nombre']
>         verbose_name, verbose_name_plural = "Autor", "Autores"
>
> class Categoria(BaseModel):
>     """categorias para articulos"""
>     nombre = models.CharField(blank=True,  max_length=80)
>     slug = models.SlugField()
>
>     def __unicode__(self):
>         return self.nombre
>
>     def get_absolute_url(self):
>         return "/categoria/%s/" % (self.slug)
>
>     class Meta:
>         ordering = []
>         verbose_name, verbose_name_plural = "Categoría", "Categorías"
>
> ### these don't:
> class Edicion(BaseModel):
>     """Una edicion, con titulo, fecha"""
>
>     titulo = models.CharField(max_length=200)
>     numero = models.IntegerField(unique=True)
>     diseno = models.ForeignKey("Diseno", verbose_name="Diseño")
>     fecha_de_publicacion = models.DateField()
>     publicar = models.BooleanField()
>
>     def __unicode__(self):
>         return self.titulo
>
>     def get_absolute_url(self):
>         if self.fecha_de_publicacion:
>             return "/portadas/%s-%s/%s" % (
>                 self.fecha_de_publicacion.year,
>                 slugify(self.titulo),
>                 self.numero)
>
>     class Meta:
>         ordering = ['-numero']
>         verbose_name, verbose_name_plural = "Edición", "Ediciones"
>
> class Dossier(BaseModel):
>     """Un dossier que contiene varios artículos"""
>     titulo = models.CharField(max_length=200)
>     subtitulo = models.CharField(blank=True,  max_length=200)
>     texto = models.TextField(blank=True)
>     edicion = models.ForeignKey(Edicion)
>     imagen = models.ImageField(upload_to="dossier")
>     ubicacion = models.IntegerField("Ubicación en portada",
> choices=ubicacion_choices, default=1)
>
>     class Meta:
>         ordering = []
>         verbose_name, verbose_name_plural = "Dossier", "Dossieres"
>
>     def __unicode__(self):
>         return "%s" % self.titulo
>
>     def get_absolute_url(self):
>         return "/dossier/%s/%s/" % (slugify(self.titulo), self.id)
>
> ### in admin.py:
> class ArticuloAdmin(admin.ModelAdmin):
>     list_display = ( 'autor','categoria','edicion','dossier')
>     list_filter = ('autor','categoria','edicion','dossier')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to