ForeignKey field with blank=True and null=True in list_display breaks admin
When you have a model with a ForeignKey
to another model with blank=True
and null=True
and use the foreign key in list_editable
and the value is indeed "null" (i.e. no relation exists), the admin interface breaks with the following message:
Caught an exception while rendering: invalid literal for int() with base 10: ''
This is the code to reproduce it:
# models.py
from django.db import models
class Brand(models.Model):
name = models.CharField(max_length=32, blank=True)
class Bicycle(models.Model):
brand = models.ForeignKey(Brand, blank=True, null=True)
kind = models.CharField(max_length=32)
#admin.py
from django.contrib import admin
from eplister.hello.models import *
class BrandAdmin(admin.ModelAdmin):
model = Brand
class BicycleAdmin(admin.ModelAdmin):
model = Bicycle
list_display = ('kind', 'brand', )
list_display_links = ('kind', )
list_editable = ('brand', )
admin.site.register(Brand, BrandAdmin)
admin.site.register(Bicycle, BicycleAdmin)
Change History
(8)
Cc: |
deniz.a.m.dogan@… added
|
Summary: |
ForeignKey field with blank=True and null=True breaks list_editable → ForeignKey field with blank=True and null=True in list_display breaks admin
|
milestone: |
→ 1.2
|
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to anonymous
|
Status: |
new → assigned
|
Owner: |
changed from anonymous to Daniel Gonzalez Gasull
|
Status: |
assigned → new
|
Resolution: |
→ worksforme
|
Status: |
new → closed
|
I just noticed that the following even smaller admin declaration breaks the admin with the same error message. Change the BicycleAdmin to the following: