﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15833	Exclude not working with ForeignKey in admin Inlnes	claytongulick	nobody	"I have a simple model:

{{{
class ImageFile(models.Model):
    name = models.CharField(max_length=50, help_text=""The textual name for the image, maximum of 50 chars"")
    gallery = models.ForeignKey(Gallery,help_text=""Select the gallery that this image belongs to"",blank=True,null=True)
    image_file = models.ImageField(upload_to=""site/%s/images/""%(settings.SITE,),help_text=""Select an image file to upload"")
    display_order = models.IntegerField(blank=True,null=True,help_text=""An optional field used for ordering the rows visually"")
    content_type = models.ForeignKey(ContentType) #reference to the magic contentTypes table
    object_id = models.PositiveIntegerField() #the generic ID of the table we're relating to
    content_object = generic.GenericForeignKey('content_type','object_id') #a generic reference is a relation that defines a) the id of the table we refer to, and b) the id of the row we're rel

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ['display_order']

}}}

Using that model as an inline, I want to exclude the gallery field, because it is optional, like this:

{{{
class ImageFileInline(generic.GenericTabularInline):
    model=ImageFile
    exclude=('gallery',)

}}}

That results in this error: 

ImproperlyConfigured at /admin/consumer/product/add/
ImageFileInline cannot exclude the field 'gallery' - this is the foreign key to the parent model Gallery.

However, if I use this instead, it works fine:
{{{
class ImageFileInline(generic.GenericTabularInline):
    model=ImageFile
    fields=('name','image_file','display_order',)
}}}

If I can remove the field by not including it in the list of fields, I should also be able to exclude the field.

Thanks!
"	Bug	closed	contrib.admin	1.2	Normal	needsinfo		mathieu.agopian@…	Unreviewed	0	0	0	0	0	0
