Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

has no attribute '_meta' error when creating a ModelAdmin object

Tags:

python

django

I am new to Django and I was trying to customize the Admin interface for my model but I get an error when trying to add a ModelAdmin object. My code and error is included below. If i take out the BlogAdmin object from the register statement, I don't get any errors and the site loads fine.

Thanks for your help!

class Blog(models.Model):
    name = models.CharField(max_length=300)
    url = models.URLField()

class BlogAdmin(admin.ModelAdmin):
    list_display = ['name', 'url']
    search_fields = ["name"]

admin.site.register([Blog,BlogAdmin])

I get the following error:

type object 'BlogAdmin' has no attribute '_meta'

Exception Location:     /Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/site-packages/django/contrib/admin/sites.py in register, line 80
Python Executable:  /Users/Bilal/Development/Django/ENV/traveller3/bin/python
Python Version:     2.7.1
Python Path:    

['',
 '/Applications/PyCharm.app/helpers/pydev',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/site-packages/MySQL_python-1.2.3c1-py2.7-macosx-10.7-intel.egg',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/site-packages/scikit_learn-0.9-py2.7-macosx-10.7-intel.egg',
 '/Users/Bilal/Development',
 '/Library/Python/2.7/site-packages/pip-1.0.2-py2.7.egg',
 '/Users/Bilal/Development/scrapyard',
 '/Applications/PyCharm.app/helpers',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python27.zip',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/plat-darwin',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/plat-mac',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/Bilal/Development/Django/ENV/traveller3/Extras/lib/python',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/lib-tk',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/lib-old',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/site-packages',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/site-packages/PIL',
 '/Library/Python/2.7/site-packages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Users/Bilal/Development/Django/ENV/traveller3/lib/python2.7/site-packages/IPython/extensions']
like image 677
CodeMonkeyB Avatar asked Apr 26 '12 02:04

CodeMonkeyB


Video Answer


1 Answers

When you write:

admin.site.register([Blog, BlogAdmin])

you register in admin two models: Blog and BlogAdmin, you must register Model and ModelAdmin for it, like this:

admin.site.register(Blog, BlogAdmin) 
like image 74
laqie Avatar answered Oct 18 '22 20:10

laqie