Opened 18 years ago

Closed 18 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: dev
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

Description

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 by anonymous, 18 years ago

Please clarify

comment:2 by Aidas Bendoraitis <bendoraitis@…>, 18 years ago

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:
        pass

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

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 http://example.com/admin/myapp/person/, 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 by Chris Beaven, 18 years ago

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

comment:4 by Gary Wilson <gary.wilson@…>, 18 years ago

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