Opened 10 years ago
Closed 10 years ago
#23545 closed Bug (duplicate)
Generic relation with ForeignKey gives a 400 Bad Request error in Django Admin
Reported by: | Matthias Pronk | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.7 |
Severity: | Normal | Keywords: | django admin generic concenttypes badrequest |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Can you please test with the
stable/1.7.x
branch? This looks like a duplicate of #23431 which will be fixed in 1.7.1, but please reopen if not.