0👍
you don’t necessarily need an admin.py file,
just import the admin module in your models.py file,
from django.contrib import admin
and for each model do the following:
admin.site.register(model1)
admin.site.register(model2)
However, this is not best practice, but since it’s just a tutorial, it will work.
You also need to uncoment the relevant lines in the urls.py file
- [Answered ]-Python cant make dictionary from list of dictionaries
- [Answered ]-Django Admin – Disable Update For FK Fields
- [Answered ]-NoReverseMatch at /
- [Answered ]-In django, why get_or_create doesn't work if the items contain ForeignKey
- [Answered ]-Django MEDIA_ROOT, MEDIA_URL etc
0👍
I think I had the same frustrations following the DjangoProject tutorial – however, when I cross-referenced it with with the DjangoBook tutorial (for the same version, I believe, 1.5.1), I found that an admin.py
file was not necessarily created after a python manage.py startapp xyz
command — moreover, I also uncommented all of the admin options in urls.py
, views.py
, and settings.py
– so a bit of a mix of what Neal and Ibrahim said
- [Answered ]-Django administration styling: Change "Site administration" and subheadings
- [Answered ]-How to render django-allauth templates
- [Answered ]-Django dict in template
- [Answered ]-Custom Filter in Django Admin returns SuspiciousOperation
- [Answered ]-Django queries does datatype matter?
0👍
You have to create your own admin.py file in the app if you want it. Indeed, this file is optionnal and isn’t created by startapp.
If you want a default template to begin your admin.py, it should be:
from django.contrib import admin
from models import Model1, Model2
class Model2Admin(admin.ModelAdmin):
list_display = ('title', 'content', 'date')
# Just an example, chekc docs and tutorials for more info.
admin.site.register(Model1)
admin.site.register(Model2, Model2Admin)
- [Answered ]-Django Cannot update a query once a slice has been taken
- [Answered ]-Cleaning up after a unit test that asserts an IntegrityError is thrown
0👍
The reason there is no default admin.py
is because you don’t have any models yet when you create your new application; so there is nothing to add to the admin section.
Further, you may not want to admin all the models in your application; or you may be creating an application that does not need any admin hookups; or you may not be using the admin application at all in your project.
Since django cannot decide this for you, there is no default admin.py
generated.
To create one, if you are following the tutorial – simply keep reading and in part two you’ll create the admin.py
file when you learn about the admin contrib app and how to integrate it with your custom models.
- [Answered ]-Query to retrieve neighbors is too slow
- [Answered ]-Override page.html template from an app