Opened 13 years ago

Closed 12 years ago

#2280 closed defect (worksforme)

Models, that have not obligatory many-to-one relationships and have no related model set, are not listed.

Reported by: Aidas Bendoraitis <bendoraitis@…> Owned by: Adrian Holovaty
Component: contrib.admin Version: master
Severity: critical Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This error occurs on Django 0.95 ('post-magic-removal').

When model A relates with model B by many-to-one relationship and that relationship is not obligatory (blank=True is set), only these A-classed objects that have related B-classed objects being set, are displayed in the Django contributed administration on the list page.

A-classed objects, that have no not obligatory related B-classed objects set, are not listed in the Django contributed administration on the list page.

Change History (4)

comment:1 Changed 13 years ago by anonymous

Please clarify

comment:2 Changed 13 years ago by Aidas Bendoraitis <bendoraitis@…>

OK. Here is a simple example. Let's say we have models Occupation and Person, where one Person can have one Occupation, and one Occupation can be taken by many People (Persons). Our models would look like this in the code:

from django.db import models

class Occupation(models.Model):
    title = models.CharField(maxlength=200)
    class Admin:

class Person(models.Model):
    occupation = ForeignKey(Occupation, blank=True)
    name = models.CharField(maxlength=200)
    class Admin:

Then we create Occupations

  • "Programmer"
  • "Manager"
  • "Designer"

and Persons

  • "Mr. Smith" who is a "Manager"
  • "Tom Anderson" who is a "Programmer"
  • "Trinity", who has no Occupation.

Now if we go to, we will get only "Mr. Smith" and "Tom Anderson" listed, because they have their Occupations set. And that is an error I am reporting.

comment:3 Changed 12 years ago by Chris Beaven

I think you need to set null=True as well in your ForeignKey

comment:4 Changed 12 years ago by Gary Wilson <gary.wilson@…>

Resolution: worksforme
Status: newclosed

I have confirmed, without null=True leaving occupation blank raises a database error as it should, and with null=True the Person gets added just fine and shows on the changelist page.

Note: See TracTickets for help on using tickets.
Back to Top