Model not appearing in django admin

74 views
Skip to first unread message

Thomas Brightwell

unread,
Aug 12, 2014, 4:50:21 PM8/12/14
to django...@googlegroups.com
I am trying to manage the data in a model through the default django admin site. I have several apps, which have all been included in INSTALLED_APPS, and I am registering the model with the default django admin. I have included the django admin app in urls.py and have verified that I am the superuser with all permissions. I know the model is importing because it is included in the permission settings, but the option to edit / create new model objects for Retailer is not available on the admin home page. 

Any pointer in the right direction would be appreciated. 

===================

webappconf/settings.py

## APPLICATION DEFINITION
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'webapp',
    'scrape',
    'style',
)

[...]

ROOT_URLCONF = 'webappconf.urls'

webappconf/urls.py

from django.contrib import admin
[...]
url(r'^admin/django_admin/', include(admin.site.urls)),

webapp/models.py

# Retailers
class Retailer(Model):
    display_name = CharField(max_length=50)
    source = CharField(max_length=50)
    logo = CharField(max_length=100)
    basic_descripion = TextField(max_length=2000)

    class Meta:
        db_table = 'retailer'

webapp/admin.py

from django.contrib import admin
from webapp.models import Retailer

class RetailerAdmin(admin.ModelAdmin):
    pass
admin.site.register(Retailer, RetailerAdmin)

From the permission options for superuser (who has all permissions)

webapp | retailer | Can add retailer
webapp | retailer | Can change retailer
webapp | retailer | Can delete retailer

chedi toueiti

unread,
Aug 13, 2014, 12:01:21 AM8/13/14
to django...@googlegroups.com
Hi,

You can start by entering the model url manually after logging to the admin interface, in your case it would be

http://[host name]:[port]/admin/django_admin/webapp/retailer

don't forget to set your DEBUG to True in the settings.py and if you are restart your server if you are running gunicorn or anything alike.

Collin Anderson

unread,
Aug 13, 2014, 1:50:14 AM8/13/14
to django...@googlegroups.com
Do you have admin.autodiscover() in your urls.py? (assuming you're not using version 1.7)

Thomas Brightwell

unread,
Aug 13, 2014, 6:27:57 AM8/13/14
to django...@googlegroups.com
Chedi,

Thanks for the quick response.


Page not found (404)
Request Method: GET
Using the URLconf defined in webappconf.urls, Django tried these URL patterns, in this order:
^$
^search/$
^product/(?P<source_id>\w+)/$
^accounts/login/$
^accounts/logout/$
^search/(?P<room>[-\w]+)/$
^search/(?P<room>[-\w]+)/(?P<cat_a>[-\w]+)/$
^search/(?P<room>[-\w]+)/(?P<cat_a>[-\w]+)/(?P<cat_b>[-\w]+)/$
^admin/cat/$
^admin/cat/unaccepted/$ [name='cat_unaccepted']
^admin/cat/deferred/$
^admin/cat/api/next_unaccepted/$
^admin/cat/api/next_deferred/$
^admin/cat/api/item/(?P<source_id>\w+)/$
^admin/cat/api/accept_item/$
^admin/cat/api/defer_item/$
^admin/edit/(?P<source_id>\w+)/$
^admin/scraping_stats/$
^admin/scraping_stats/details/(?P<spider_name>[A-Za-z0-9-_]+)/$
^admin/scraping_stats/api/load_all_spider_stats/$
^admin/scraping_stats/api/load_all_retailer_stats/$
^admin/scraping_stats/api/load_spider_stats/(?P<spider_name>[A-Za-z0-9-_]+)/$
^admin/scraping_stats/counts/$
^admin/django_admin/ ^$ [name='index']
^admin/django_admin/ ^login/$ [name='login']
^admin/django_admin/ ^logout/$ [name='logout']
^admin/django_admin/ ^password_change/$ [name='password_change']
^admin/django_admin/ ^password_change/done/$ [name='password_change_done']
^admin/django_admin/ ^jsi18n/$ [name='jsi18n']
^admin/django_admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$ [name='view_on_site']
^admin/django_admin/ ^auth/group/
^admin/django_admin/ ^auth/user/
^admin/django_admin/ ^(?P<app_label>auth)/$ [name='app_list']
^style/
The current URL, admin/django_admin/webapp/retailer, didn't match any of these.

Thomas Brightwell

unread,
Aug 13, 2014, 6:28:30 AM8/13/14
to django...@googlegroups.com
Collin,

I'm running django v1.7c1

chedi toueiti

unread,
Aug 13, 2014, 6:55:09 AM8/13/14
to django...@googlegroups.com
I see that you have other routes beginning with ^admin/, this can some time cause the non inclusion of certain urls depending on the order in which they appear in the urls.py file. Can you comment the other ones and just keep

url(r'^admin/django_admin/', include(admin.site.urls))

to eliminate this possibility.

Thomas Brightwell

unread,
Aug 13, 2014, 6:58:54 AM8/13/14
to django...@googlegroups.com
Chedi,

I commented out the other lines leaving this:

urlpatterns = patterns('',
    # ##################
    # DJANGO ADMIN
    # ##################
    url(r'^admin/django_admin/', include(admin.site.urls)),

    # ##################
    # STYLE TEST
    # ##################
    url(r'^style/', include('style.urls')),
)


Page not found (404)
Request Method: GET
Using the URLconf defined in webappconf.urls, Django tried these URL patterns, in this order:
^admin/django_admin/ ^$ [name='index']
^admin/django_admin/ ^login/$ [name='login']
^admin/django_admin/ ^logout/$ [name='logout']
^admin/django_admin/ ^password_change/$ [name='password_change']
^admin/django_admin/ ^password_change/done/$ [name='password_change_done']
^admin/django_admin/ ^jsi18n/$ [name='jsi18n']
^admin/django_admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$ [name='view_on_site']
^admin/django_admin/ ^auth/user/
^admin/django_admin/ ^auth/group/
^admin/django_admin/ ^(?P<app_label>auth)/$ [name='app_list']
^style/
The current URL, admin/django_admin/webapp/retailer, didn't match any of these.

Collin Anderson

unread,
Aug 13, 2014, 12:58:17 PM8/13/14
to django...@googlegroups.com
Wow. Is the admin.py file actually getting run? (try a print statement or try throwing an exception)

Thomas Brightwell

unread,
Aug 13, 2014, 1:13:24 PM8/13/14
to django...@googlegroups.com
Collin,

Thanks for the help. I updated my admin.py with this (also been trying other variations of the register):

from django.contrib import admin
from .models import Retailer

@admin.register(Retailer)
class RetailerAdmin(admin.ModelAdmin):
    pass

print 'foo'
raise Exception()

Restarted my webserver and http://localhost:8000/admin/django_admin/ loads without error. I have debugged right through the loading on startup and checked django-admin is attempting a module import of the webapp.admin, and it does seem to be trying.

Collin Anderson

unread,
Aug 13, 2014, 1:34:53 PM8/13/14
to django...@googlegroups.com
Do you have a webapp/__init__.py file? Can you import webapp.admin in
./manage.py shell?

Thomas Brightwell

unread,
Aug 13, 2014, 1:38:51 PM8/13/14
to django...@googlegroups.com

Yes, have an __init__.py file. And yes, works fine importing.

bash-3.2$ ./manage.py shell

Python 2.7.5 (default, Mar  9 2014, 22:15:05) 

In [1]: import webapp.admin

In [2]: 


webapp directory listing:

bash-3.2$ ls

__init__.py admin admin.pyc item migrations models.pyc templates tests view

__init__.pyc admin.py fixtures locale models.py search templatetags util views.pyc

Thomas Brightwell

unread,
Aug 13, 2014, 1:44:03 PM8/13/14
to django...@googlegroups.com
Ok, figured it. I have an admin folder as well as admin.py so they're conflicting. 

Removing it solved the issue and Retailer now appears in the admin interface. 

Thanks for the debugging steps!

Cheers,

Tom
Reply all
Reply to author
Forward
0 new messages