#23545: Generic relation with ForeignKey gives a 400 Bad Request error in Django
Admin
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
mjepronk | Status: new
Type: Bug | Version: 1.7
Component: | Keywords: django admin generic concenttypes
contrib.admin | badrequest
Severity: Normal | Has patch: 0
Triage Stage: | UI/UX: 0
Unreviewed |
Easy pickings: 0 |
-------------------------+-------------------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/23545>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.5cc59c02c3b334b139dea7a424f140d8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.