38π
Hmmmmβ¦Try change include of your app in settings.py:
From:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'game',
....
To:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'YOUR_PROJECT.game',# OR 'YOUR_PROJECT.Game'
204π
The problem reported can be because you skipped registering the models for the admin site. This can be done, creating an admin.py
file under your app, and there registering the models with:
from django.contrib import admin
from .models import MyModel
admin.site.register(MyModel)
- [Django]-What is the difference between null=True and blank=True in Django?
- [Django]-Using Pylint with Django
- [Django]-Django β SQL bulk get_or_create possible?
36π
Had the same issue with Django 2.0.
The following code didnβt work:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from users import models
admin.register(models.User, UserAdmin)
It turns out the line
admin.register(models.User, UserAdmin)
should have been
admin.site.register(models.User, UserAdmin)
Since I didnβt get any warnings, just wanted to point out this thing here too.
- [Django]-Class has no objects member
- [Django]-"gettext()" vs "gettext_lazy()" in Django
- [Django]-How to set environment variables in PyCharm?
10π
I know this has already been answered and accepted, but I felt like sharing what my solution to this problem was, maybe it will help someone else.
My INSTALLED_APPS
looked like this:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'core', # <---- this is my custom app
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'south',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
See, I put my app before Djangoβs admin app, and apparently it loads them in that order. I simply moved my app right below the admin, and it started showing up π
- [Django]-How to reset Django admin password?
- [Django]-Django: remove a filter condition from a queryset
- [Django]-Is this the right way to do dependency injection in Django?
6π
For Django 1.10 helped to me to register the Model following way with (admin.ModelAdmin) at the end
from django.contrib import admin
from .models import YourModel
admin.register(YourModel)(admin.ModelAdmin)
- [Django]-Django β Overriding the Model.create() method?
- [Django]-Why does Django's render() function need the "request" argument?
- [Django]-Get list item dynamically in django templates
6π
I had the same issue. Done everything right. But I didnβt have permission to view the model.
Just give the required permission (view/add/edit/etc) and then check again.
Give Permission using admin panel:
- Login to the site using the credentials for your superuser account.
- The top level of the Admin site displays all of your models, sorted by "Django application". From the Authentication and Authorization section, you can click the Users or Groups links to see their existing records.
- Select and add the required permission
Select and add the required permission
refer this to add/change permission through the admin panel
Alternative:
Using code
refer Official Django Doc
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
- [Django]-Running a specific test case in Django when your app has a tests directory
- [Django]-Django templates: verbose version of a choice
5π
Itβs probably very rare but I had an issue today where the permissions on the admin.py file I had created were corrupt and thus made it unreadable by django. I deleted the file and recreated it with success.
Hope that saves someone, should they stumble here with my problem.
- [Django]-Allowing only super user login
- [Django]-What are the limitations of Django's ORM?
- [Django]-How to resize an ImageField image before saving it in python Django model
5π
I struggled with registering my models (tried all the suggestions above) too until I did a very simple thing. I moved my admin.py out of the directory up to the project directory β refreshed the admin screen and moved it back and voila into the models app directory β they all appeared instantly. Iβm using PyCharm so not sure if that was causing some problems.
My setup is exactly what the Django manual says β
models.py
class xxx(models.Model):
....
def __str__(self): # __str__ for Python 3, __unicode__ for Python 2
return self.name
admin.py
from .models import xxx
admin.site.register(xxx)
- [Django]-Django set default form values
- [Django]-Django: remove a filter condition from a queryset
- [Django]-Django: Set foreign key using integer?
4π
I am using digital ocean and also ran into this issue. The solution was a service restart. I used
service gunicorn restart
and that got the model to show up
- [Django]-Django: Get list of model fields?
- [Django]-How to pull a random record using Django's ORM?
- [Django]-How do I convert a Django QuerySet into list of dicts?
3π
I just had to restart apache service. service apache2 restart. Then new models shown up.
- [Django]-Django delete FileField
- [Django]-Unittest Django: Mock external API, what is proper way?
- [Django]-How to add data into ManyToMany field?
3π
I had the same issue. Few of my models were not showing in the django admin dashbaord because I had not registered those models in my admin.py file.
//Import all the models if you have many
from store.models import *
admin.site.register(Order)
admin.site.register(OrderItem)
This fixed it for me. Just register and refresh your webpage and the models will be visible in the admin dashboard
- [Django]-Django templates: verbose version of a choice
- [Django]-How to unit test file upload in django
- [Django]-Django: sqlite for dev, mysql for prod?
2π
I have the same problem. I solve this to add register of admin to admin.py
.
And I donβt need to add extra class.
Like:
from jalka.game.models import Game
from django.contrib import admin
admin.site.register(Game)
Enviroment: Win10γDjango 1.8
- [Django]-Get user profile in django
- [Django]-How to limit the maximum value of a numeric field in a Django model?
- [Django]-Delete multiple objects in django
2π
I had the same issue and i resolved it as follow
first go to your app.py file and copy the class name.
from django.apps import AppConfig
class **ResumeConfig**(AppConfig):
name = 'resume'
now go to setting.py and place it in application definition as follow:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
**'resume.apps.ResumeConfig'**
]
save and run the commands in the terminal
python manage.py makemigrations
python manage.py migrate
run your server and go to /admin
your problem will be solved
- [Django]-Why doesn't django's model.save() call full_clean()?
- [Django]-Django β Login with Email
- [Django]-Extend base.html problem
2π
you just need to register your model.
got to admin.py file of the same app and write,
from .models import "Modelname"
admin.site.register(("Modelname"))
#create tuple to register more than one model
- [Django]-How do you detect a new instance of the model in Django's model.save()
- [Django]-Can we append to a {% block %} rather than overwrite?
- [Django]-How to use pdb.set_trace() in a Django unittest?
1π
I would also like to add, that I did everything these answers said, except I did not enter on the command line sudo service apache2 restart
which I needed to make the changes take effect. (Because I was testing on a live server on port 80 on amazon web services. I was also using an Ubuntu operating system.) That solved it for me. I hope this might help somebody.
- [Django]-How to tell if a task has already been queued in django-celery?
- [Django]-What's the purpose of Django setting βSECRET_KEYβ?
- [Django]-How to solve "Page not found (404)" error in Django?
1π
I got the same issue,
After restart my development server model is showing in admin page.
- [Django]-How to delete a record in Django models?
- [Django]-H14 error in heroku β "no web processes running"
- [Django]-Override existing Django Template Tags
1π
Change your admin code to this:
from django.contrib import admin
from .models import Game
class GameAdmin(admin.ModelAdmin):
list_display = ['type', 'teamone', 'teamtwo', 'gametime']
admin.site.register(Game, GameAdmin)
Also make sure the app is included in settings.py file and make sure youβre importing the right name for your model. Another reason that can bring about this issue is putting a comma (,) at the end of your model fields as though it a python list.
- [Django]-How to set up a PostgreSQL database in Django
- [Django]-Combining Django F, Value and a dict to annotate a queryset
- [Django]-Django β Clean permission table
1π
My new model not showing up on Admin page due to me using ADMIN_REORDER(https://pypi.org/project/django-modeladmin-reorder/) in settings.py to control model order, added a while back and forgotten. Added the new model to settings.py and it shows up.
- [Django]-Django/DRF β 405 Method not allowed on DELETE operation
- [Django]-Remove pk field from django serialized objects
- [Django]-Django: how to do calculation inside the template html page?
0π
Adding to what Saff said, your settings.py
should be like this:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'YOUR_PROJECT',
# And
'YOUR_PROJECT.Foo',
'YOUR_PROJECT.Bar',
)
- [Django]-405 "Method POST is not allowed" in Django REST framework
- [Django]-Django models: Only permit one entry in a model?
- [Django]-Django {% if forloop.first %} question
0π
The mistake might be at views.py
in your βdefβ you should check if you got
If mymodel.is_valid():
mymodel = model.save()
I will give you a piee of my code so you would understand it
@login_required(login_url='/home/')
def ask_question(request):
user_asking = UserAsking()
if request.method == "POST":
user_asking = UserAsking(request.POST)
if user_asking.is_valid():
user_asking.save()
return redirect(home)
return render(request, 'app/ask_question.html', {
'user_asking': user_asking,
})
`UserAsking is a form.
i hope i did help you
- [Django]-How do you skip a unit test in Django?
- [Django]-Google Static Maps URL length limit
- [Django]-Django: remove a filter condition from a queryset
0π
One of the possible reasons is that you do not close old python processes.
- [Django]-How can I change the default Django date template format?
- [Django]-Django filter many-to-many with contains
- [Django]-Django β "Incorrect type. Expected pk value, received str" error
0π
I had a similar issue on an instance of django mounted in a docker container. The code was correct but changes to admin.py were not appearing in django admin.
After quitting the django process and remounting the container with docker-compose up
, the added models became available in django admin.
- [Django]-Django REST framework: non-model serializer
- [Django]-How do I remove Label text in Django generated form?
- [Django]-How do I perform query filtering in django templates
0π
I had all my Admin classes in a folder ./sites/
which only worked because of cercular dependencies I had. I fixed them, and everything else stopped working.
When I renamed that directory from ./sites/
to ./admin/
it worked.
- [Django]-Django gives Bad Request (400) when DEBUG = False
- [Django]-Best practice for Django project working directory structure
- [Django]-Django or Django Rest Framework
0π
Another thing to point out is that you should make sure youβre signed in with a superuser.
It could be that you are signed in with a user who has limited permission on view capacity so try that.
I in Django 2.0 I still register my app using just the name of the app i.e βgameβ. But the issue was in the logged in user permissions.
- [Django]-When to use Serializer's create() and ModelViewset's perform_create()
- [Django]-Having Django serve downloadable files
- [Django]-Django-debug-toolbar not showing up
0π
I was updating a remote server with code from local, but the remote server was still using the old models in the admin screen. Everything looked exactly the same between my local and the remote server β the database tables matched and the code was also identical.
The problem turned out the remote server was running using the venv environment. After running source venv/bin/activate
and then doing the migrations, the admin showed all the new models.
- [Django]-PyCharm: DJANGO_SETTINGS_MODULE is undefined
- [Django]-Checking for empty queryset in Django
- [Django]-How to remove all of the data in a table using Django
0π
If you have multiple models to register then use.
admin.site.register((Model1 , Model2 , Model3))
or
admin.site.register([Model1 , Model2 , Model3])
in your admin.py file.
- [Django]-How to go from django image field to PIL image and back?
- [Django]-How do you catch this exception?
- [Django]-Get object by field other than primary key
0π
I have the same error but I have not mentioned my app in INSALLED_APPS
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'myapp.apps.myappConfig',
)
I have already registered the model but forgot to mention my app in INSTALLED_APPS and after mentioning it works for me
- [Django]-Django error when installing Graphite β settings.DATABASES is improperly configured. Please supply the ENGINE value
- [Django]-How to rename items in values() in Django?
- [Django]-How can I create a deep clone of a DB object in Django?
0π
For me, migration was an issue. If you created this new app, try doing the following:
python manage.py makemigrations <name_of_your_app>
python manage.py migrate <name_of_your_app>
You do not need to include all admin.site.register
in a single app, you could specify them in their corresponding app at the admin.py
file.
- [Django]-Serving Media files during deployment in django 1.8
- [Django]-Pylint "unresolved import" error in Visual Studio Code
- [Django]-Using Pylint with Django
0π
I had this same issue, django=4.0
with docker-compose
i was not using ModelAdmin
, turns out registering multiple Models in one call to admin.site.register
errors out when running migration.
So doing
admin.site.register(ModelA, ModelB)
did not work. instead, you I did something like
admin.site.register(ModelA)
admin.site.register(ModelB)
I hope it helps anyone dockerizing their Django App
- [Django]-Readonly models in Django admin interface?
- [Django]-Is there a way to loop over two lists simultaneously in django?
- [Django]-How do you perform Django database migrations when using Docker-Compose?
0π
Give your user "Superuser status" through the edit user functionality in the admin panel.
Most probably the user you are signed in is not a superuser and doesnβt have the required permissions for the newly created models.
In Django, after new models are created and migrated, the permissions of the existing users are not updated. Only the users with Superuser status can by default view, add, change and delete records for these models.
To fix the problem and avoid it in the future give "Superuser status" to your development user.
- [Django]-How to get Django and ReactJS to work together?
- [Django]-Assign variables to child template in {% include %} tag Django
- [Django]-Multiple Database Config in Django 1.2
-1π
You Make sure You have Added your Model to
admin.py file .
Example : if your model is Contact.
from django.contrib import admin
from .models import Contact
admin.site.register((Contact))
Now your issue might be resolved if not try restarting your server.
- [Django]-Problems with contenttypes when loading a fixture in Django
- [Django]-Django gunicorn sock file not created by wsgi
- [Django]-Select between two dates with Django
- [Django]-Django β accessing the RequestContext from within a custom filter
- [Django]-Filtering using viewsets in django rest framework
- [Django]-RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS