Contents
django-setup is a Django starter that dates from 2019. It is an older project, not a maintained template, and it shows. The header of web/settings.py says it was generated with Django 5.2.4, yet requirements.txt pins nothing: its first line is just Django, followed by eleven more unpinned package names.
Around the core it has a REST API, a Channels chat and Celery workers, all started through Docker Compose. I am going to ignore most of that and look at the plain CRUD screen in apps/console, because it is the part a beginner can copy and understand in one sitting.
One model, four named URLs
Item in apps/console/models.py has 27 fields. It reads like a catalogue of field types: decimals, choices, a foreign key, a many-to-many, an image, a file and a JSON field. The form only exposes 16 of them. The routes are short:
urlpatterns = [
path('', views.item_list, name='item_list'),
path('create/', views.item_create, name='item_create'),
path('update/<int:pk>/', views.item_update, name='item_update'),
path('delete/<int:pk>/', views.item_delete, name='item_delete'),
]The name= arguments are the useful part. Templates link with {% url 'item_update' item.pk %} instead of a typed path, so renaming update/ later breaks nothing. <int:pk> captures the id and hands it to the view.
One function, two jobs
Here is the create view as it exists in the repo:
def item_create(request):
if request.method == 'POST':
form = ItemForm(request.POST, request.FILES)
if form.is_valid():
try:
item = form.save(commit=False)
item.created_by = request.user if request.user.is_authenticated else None
item.save()
form.save_m2m()
messages.success(request, 'Item created successfully!')
return redirect('item_list')
except Exception as e:
messages.error(request, f'Error creating item: {str(e)}')
else:
form = ItemForm()
return render(request, 'console/item_form.html', {'form': form})A first visit is a GET, so it lands in the else branch and renders an empty form. Submitting sends a POST. The form is built from request.POST and request.FILES, and is_valid() runs the field rules plus the clean_name and clean_price hooks in forms.py. If the data is bad, the function falls through to the last line and renders the same form again, now carrying its errors.
save(commit=False) returns an unsaved Item, which gives the view a chance to set created_by. That field is not in the form. The tags field is many-to-many, and Django cannot link those rows until the item has an id, so form.save_m2m() runs after item.save(). The redirect on success means a browser refresh does not resubmit the form.
item_update has the same shape. It loads the row with get_object_or_404(Item, pk=pk), passes instance=item to the form and calls form.save().
One template for create and edit
item_form.html serves both screens. The heading is {% if item %}Edit Item{% else %}Create Item{% endif %}, and only the update view passes item to this template. The form tag carries enctype="multipart/form-data", which the image and document fields need.
The Bootstrap classes live in Python: ItemForm sets 'class': 'form-control' in each widget's attrs. That is why the template can print {{ form.name }} and get a styled input.
Delete is two steps. A GET renders a confirmation page, and only a POST from its {% csrf_token %} form deletes the row.
How Docker runs it
docker-compose.yml defines five services: db, redis, django, celery and celery-beat. The last two reuse the same image with a different command. The django service has no command of its own, so it runs the CMD from the Dockerfile, which starts daphne on port 8000. A comment there explains the choice: an ASGI server is needed for the chat's WebSocket.
Settings default the database host to db and Redis to redis://redis:6379/0, so the Compose service names double as hostnames. The README's commands are:
docker-compose up --build
docker-compose exec django python manage.py makemigrations
docker-compose exec django python manage.py migrate
docker-compose exec django python manage.py createsuperuserWhat I would change today
Configuration
Pin the packages in requirements.txt, and pin the postgres and redis images instead of latest. Move the hard-coded SECRET_KEY and the database password out of settings.py and the Compose file, and replace ALLOWED_HOSTS = ['*'] with real hostnames.
Unfinished code
views.py contains category and tag views, but console/urls.py routes only items and templates/console/ has no category or tag pages. SimpleItemForm and BulkActionForm are imported and never used. The list view builds a search form that its template never renders. I would finish these or delete them.
Behaviour I would check
The console views have no login_required, while the chat views do, so anyone can create and delete items. slug is unique, may be blank, is left out of the form and is set nowhere. I have not run it, so this is a reading of the code, but I expect the second item to hit the unique constraint. The four tests.py files are still the empty stub.
Even so, the create, update and delete trio above is a sound pattern for a first admin-style screen. I would keep its shape and rebuild the rest.
Found this useful? Share it with your team.