If a model contains other models using ForeignKey fields, and the submodels don't have have their own explicit Admin interface (ie, have "class Admin" in their class definitions), then creating those subobjects will produce an the following kind of error:
Traceback (most recent call last):
File "/usr/local/src/django/svn-trunk/django/core/handlers/base.py" in get_response
74. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/src/django/svn-trunk/django/contrib/admin/views/decorators.py" in _checklogin
54. return view_func(request, *args, **kwargs)
File "/usr/local/src/django/svn-trunk/django/views/decorators/cache.py" in _wrapped_view_func
40. response = view_func(request, *args, **kwargs)
File "/usr/local/src/django/svn-trunk/django/contrib/admin/views/main.py" in add_stage
299. return render_change_form(model, manipulator, c, add=True)
File "/usr/local/src/django/svn-trunk/django/contrib/admin/views/main.py" in render_change_form
196. field_sets = opts.admin.get_field_sets(opts)
AttributeError at /admin/polls/license/add/
'NoneType' object has no attribute 'get_field_sets'
This error was generated for the following model. In this case, adding an "Institution" will work, but adding a "License" will produce the above error. Also, there's no way to add an "Operating System" for the same reason. All work correctly if the subobjects are explicitly declared to have Admin interfaces.
from django.db import models
class Institution(models.Model):
name = models.CharField(maxlength=200, core=True)
reference_url = models.CharField(maxlength=200, core=True)
class Admin: # because of this field, no error here
pass
def __repr__(self):
return self.name
class License(models.Model):
# no Admin class will produce an error when added
title = models.CharField(maxlength=200)
reference_url = models.URLField()
description = models.TextField()
def __repr__(self):
return self.title
class OperatingSystem(models.Model):
# no Admin class: no way to add this object as a subpart of SoftwarePackage
name = models.CharField(maxlength=200, core=True)
def __repr__(self):
return self.name
class SoftwarePackage(models.Model):
title = models.CharField(maxlength=200)
institution = models.ForeignKey(Institution, null=True)
license = models.ForeignKey(License, null=True)
operating_system = models.ManyToManyField(OperatingSystem, null=True)
open_source = models.BooleanField()
def __repr__(self):
return self.title
class Admin:
pass
I have no problem adding objects in the admin interface or in the shell. If no class Admin is specified, then then those type of objects cannot be added through the admin.