1
votes

I was creating a Django app. Doing so i enabled the Django admin site and i could see it working fine. Then i created some models and inserted data into it through the form in my app. But i am not able to see the entered values through admin panel of Django. I found that its because i havent included an admin.py file in my application folder. Then i created an admin.py file, ran syndb and tried. Now its throwing an error

ImportError at /admin/
No module named UniversityDetails.models

I will paste my admin.py, models.py and project folder structure. Please help me to solve this.

Models.py

from django.db import models

class UniversityDetails(models.Model):
    firstName = models.CharField(max_length=200)
    lastName = models.CharField(max_length=200)
    email = models.EmailField()
    password = models.TextField()
    birthday = models.TextField()
    sex = models.CharField(max_length=10)

admin.py

from universityDetails.models import *
from django.contrib import admin

admin.site.register(UniversityDetails)

Project Name :universityDB
Application Name : universityDetails

TRACEBACK

    Environment:

Request Method: GET
Request URL: http://10.1.0.90:8080/admin/
Django Version: 1.2.5
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'universityDetails',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:

    File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
      91.                         request.path_info)
    File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py" in resolve
      215.             for pattern in self.url_patterns:
    File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
      244.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/usr/local/lib/python2.6/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
      239.             self._urlconf_module = import_module(self.urlconf_name)
    File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py" in import_module
      35.     __import__(name)
    File "/home/rv/Desktop/universityDB/../universityDB/urls.py" in <module>
      5. admin.autodiscover()
    File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/__init__.py" in autodiscover
      24.             import_module('%s.admin' % app)
    File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py" in import_module
      35.     __import__(name)
    File "/home/rv/Desktop/universityDB/universityDetails/admin.py" in <module>
      1. from UniversityDetails.models import *

    Exception Type: ImportError at /admin/
    Exception Value: No module named UniversityDetails.models
5
I thought you said you changed line 1 to my version? What is the traceback when you change the import line to from universityDB.universityDetails.models import *? - Yuji 'Tomita' Tomita
This is the traceback with the modification u told me. - rv_k
This traceback says line 1 of universityDetails/admin.py is from UniversityDetails.models import * - Are you restarting the server? - Yuji 'Tomita' Tomita
yes...i am restarting the server..! - rv_k
That's so odd.. A line that doesn't exist appearing in the traceback. I've only seen something like this with old .pyc files lying around and causing mayhem. Try deleting your .pyc files. Otherwise, it's out of my league. Good luck rv_k! I gotta get to sleep. - Yuji 'Tomita' Tomita

5 Answers

3
votes

try

from universityDB.universityDetails.models import *
from django.contrib import admin

class UniversityDetailsAdmin(admin.ModelAdmin):
    fields = ['firstName ', 'lastName ']
    list_display = ('firstName ', 'lastName ')    
    search_fields = ['firstName ', 'lastName ']

admin.site.register(UniversityDetails,UniversityDetailsAdmin)
1
votes

It sounds like UniversityDetails isn't in your python path, have you added it yet?

1
votes

The typical django setup puts the project's parent directory on the Python Path, meaning your models are resolved via MyProject.MyApp.models

If you can import universityDB (you would need to or you'd have more / different problems), you should change line 1 of your admin.py to from universityDB.universityDetails.models import * and you should be set.

0
votes

Use the following :

from models import *

and put your admin.py file in your model folder

0
votes

try turning managed = false in the model name (delete the managed = false in meta of model class)