﻿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
23545	Generic relation with ForeignKey gives a 400 Bad Request error in Django Admin	Matthias Pronk	nobody	"The following simple app shows the problem:

models.py:
{{{
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType

class Tag(models.Model):
    tag = models.CharField(max_length=100)

    def __str__(self):
        return self.tag

class TaggedItem(models.Model):
    tag = models.ForeignKey(Tag)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

    def __str__(self):
	return self.tag

class Item(models.Model):
    title = models.CharField(max_length=100)

    tags = GenericRelation(TaggedItem)

    def __str__(self):
	return self.title
}}}

admin.py:
{{{
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline

from testapp.models import *

class TaggedItemInline(GenericTabularInline):
    model = TaggedItem

class ItemAdmin(admin.ModelAdmin):
    inlines = [TaggedItemInline]

admin.site.register(Item, ItemAdmin)
admin.site.register(Tag)
}}}

Now, when I open the Django Admin and create a new Item, I get a form with three empty Tag inline rows as expected. When I want to directly create a tag from the inline (using the [+] button next to the drop down to select a Tag), a popup opens which shows the error message ""400 Bad Request"". If I make the foreign key a raw id widget the same behaviour is observed when trying to pick a Tag.

This functionality still worked in Django 1.7-RC2.
"	Bug	closed	contrib.admin	1.7	Normal	duplicate	django admin generic concenttypes badrequest		Unreviewed	0	0	0	0	0	0
