# ModelAdmin Objects

**URL:** <https://forum.djangoproject.com/t/modeladmin-objects/8871>\
**Category:** Using Django\
**Created:** [July 20, 2021, 6:28am UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871 "2021-07-20T06:28:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishitkanwar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ishitkanwar/32/2905_2.png) [@ishitkanwar](https://forum.djangoproject.com/u/ishitkanwar)\
**Post date:** [July 20, 2021, 6:28am UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/1 "2021-07-20T06:28:56Z")

</div>

I am trying to register my model into the admin view using the code:

```auto
from django.contrib import admin
from mysite.polls.models import Choice, Question

# Register your models here.

admin.site.register(Question)
admin.site.register(Choice)

```

But i am getting the error: (mysite is the project name and polls is the app name)

```auto
from mysite.polls.models import Choice, Question
ModuleNotFoundError: No module named 'mysite.polls'

```

I am following the 3.1 documentation which tells us to use:

```auto
from django.contrib import admin
from myproject.myapp.models import Author

admin.site.register(Author)

```

While registering your model in admin.py

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 20, 2021, 11:36am UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/2 "2021-07-20T11:36:01Z")

</div>

Is your `polls` directory in a directory named `mysite`?  
Is `polls` listed in your INSTALLED\_APPS setting?  
Do you have an `apps.py` file in the `mysite.polls` directory?  
Do you have an empty ` __init__.py` file in `mysite.polls`?

What version of Python are you using? What version of Django?

---

<div class="post-metadata">

**Author:** ![ishitkanwar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ishitkanwar/32/2905_2.png) [@ishitkanwar](https://forum.djangoproject.com/u/ishitkanwar)\
**Post date:** [July 20, 2021, 12:45pm UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/3 "2021-07-20T12:45:20Z")

</div>

1. Yes `polls` is a directory in a directory named `mysite`  
 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/7/7b5c6658e4fbf53247b0dd0f95bf6499114fe842.jpeg)

2. Yes `polls` is listed in my `INSTALLED_APPS` setting as:

```auto
# Application definition

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

```

1. Yes i have an `apps.py` file in `polls` directory.
2. Yes there is an empty ` __init__.py` file in `polls` directory

Python version = 3.8.5 and Django version = 3.1.4

---

<div class="post-metadata">

**Author:** ![ishitkanwar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ishitkanwar/32/2905_2.png) [@ishitkanwar](https://forum.djangoproject.com/u/ishitkanwar)\
**Post date:** [July 20, 2021, 12:46pm UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/4 "2021-07-20T12:46:23Z")

</div>

First i have used the command `django-admin startproject mysite`  
Then, i created a app named polls using the command `python manage.py startapp polls`  
Now i have 2 models named `Question` and `Choice` in my `polls` app and in order to register them i have followed the step given in the documentation

 ![Capture2](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/a/a51082d9b4b0b6402c2c1cb203b46173bc7795c5.jpeg)

Link: [The Django admin site | Django documentation | Django](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/)

Just have replaced `myproject` with `mysite` as it is the name of my project and `myapp` with `polls` as that is the name of my app.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 20, 2021, 12:51pm UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/5 "2021-07-20T12:51:53Z")

</div>

The “project-level” `mysite` is your base directory - `polls` is not within the “app” `mysite`, it’s within the “project” `mysite`. Your reference to your models is then `polls.models`, not `mysite.polls.models`. (Notice that you reference it in your INSTALLED\_APPS as `polls.apps`, not `mysite.polls.apps`.)

---

<div class="post-metadata">

**Author:** ![ishitkanwar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ishitkanwar/32/2905_2.png) [@ishitkanwar](https://forum.djangoproject.com/u/ishitkanwar)\
**Post date:** [July 20, 2021, 1:27pm UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/6 "2021-07-20T13:27:01Z")

</div>

I think we are not supposed to keep an app within app anyways, then why is that (`myproject.myapp.models`)given in the documentation? Isn’t it giving unnecessary confusion to someone following the documentation:

```auto
from django.contrib import admin
from myproject.myapp.models import Author

admin.site.register(Author)

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 20, 2021, 1:51pm UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/7 "2021-07-20T13:51:30Z")

</div>

I agree, I have filed a documentation ticket for this. (There’s another situation where this would be valid, and that’s when you have your manage.py outside your project. That’s how it used to be done long ago.)

---

<div class="post-metadata">

**Author:** ![AhmdMWddh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmdmwddh/32/21707_2.png) [@AhmdMWddh](https://forum.djangoproject.com/u/AhmdMWddh)\
**Post date:** [July 21, 2021, 3:51pm UTC](https://forum.djangoproject.com/t/modeladmin-objects/8871/8 "2021-07-21T15:51:43Z")

</div>

> [@ishitkanwar](#):
>
> ```auto
> from django.contrib import admin
> from mysite.polls.models import Choice, Question
> 
> # Register your models here.
> 
> admin.site.register(Question)
> admin.site.register(Choice)
> 
> ```

You can try to import it like this:

```auto
from django.contrib import admin
from .models import Choice, Question

admin.site.register(Question)
admin.site.register(Choice)

```

Because `models.py` and `admin.py` in the same directory and you can access any file in the same directory with a dot.
