0
votes

After running a successful runserver,
To create a super user in django project, I updated the admin.py in my app directory as

from django.contrib import admin

from .models import Item

admin.site.register(Item)

by running the following

$: python manage.py createsuperuser; I am getting the below error

errorlog pastebin

I am newbie to django and python, I read in other post about circular import but couldn't figure out error.

I have taken the tutorial from Python and django youtube.

3
Well, do you have a circular import? We can't tell without seeing your models file. Also please include all relevant details here in your question, don't link to offsite. It makes it easier for future users to find your question - kylieCatt
Hi @Nicarus, as i have stated in the question itself i have read about circular import in other question from stackoverflow, as i am new to python here, can u help me figure out a solution. - krishnakant
Updating manage.py to do this sounds like a very bad idea. - Daniel Roseman
this is my first project in django. Can u suggest other way. btw it was workin fine on the tutorial(given a link for that). - krishnakant

3 Answers

1
votes

Do Not Update manage.py

There must be a file called admin.py in your app folder. Whenever you create a new app, admin.py is automatically cerated in your app directory (django-admin startapp your_app_name )

open admin.py: move your code into it.

from django.contrib import admin

from .models import Item  # Make sure you update this properly.

admin.site.register(Item)

Now Item should be listed in your admin panel.

PS: Make sure there are no circular import in your models. The error you are getting is most likely resulting from a circular import.

1
votes

You have identified the problem in this comment:

models.py : from django.db import models

Item is not something that comes with Django. You will need to define a model named Item yourself. My guess is you ahve missed a pretty important step in your tutorial (or the tutorial is wrong/missing a step). However to get your app running in the meantime add to models.py:

from django.db import models


class Item(models.Model):
    pass

This should allow you to create a superuser. Be aware this model doesn't do anything. You will either have to find the missing step of your tutorial or figure out what it supposed to be doing.

0
votes

Is your manage.py and models.py in the same directory? from .models import Item means you are trying to import the models from the same package(relative import), if not then you might need to do this(substitute app with your actual app name):

from app.models import Item

Also, it's really bad to register admin in manage.py. Django suggest doing it in the admin.py file in your app. Since admin.py is in the same package as models.py, it should just work. Check django doc about this.