I am trying to create an identical create form and list table for my models as my application is mostly CRUD based that my users will be using. The default admin form and table are already very elegantly designed and more than meet my needs.
I went through templates in
django/django/contrib/admin/templates/admin/ on github repository but I am having a hard time putting the pieces together. The HTML file names are not intuitive enough to begin with: for example, what template is used to render the model table. Or what does
change_list mean in change_list.html. What is the best way to approach this to avoid rewriting the form and table code?
I don’t exactly understand where you are stuck, but i’ll try to go at this one step at a time.
I’ll make some assumptions about what you already have:
You have implemented some models and appropriate views.
Now you would like to include those models in the django administration, right?
If thats the case, register your model in the app’s admin.py:
from django.contrib import admin
from . import models
# Register your models here.
The django administration also allows you to change some things (like the order of columns, what information is visible or editable, etc.).
Here is the documentation for changing the fields available in the add and change dialogues: Documentation
When I wanted to understand the admin, I worked from the other direction. I started with the urls and followed that through to the views. (That’s basically the order that these events occur.)
By understanding the views, I learned how the contexts were built and which templates were used as the basic template for that view. Then I followed that chain through the various templates that are included at various points to create the page.