Project Workshop — Django Blog App
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
Django · PostgreSQL · Admin
Expected effort: 5–8 focused hours · Minimum meaningful tests: 12What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | Model-Template-View vs MVC produces the specified behavior inside MTV architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | project vs app distinction produces the specified behavior inside MTV architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | settings.py: INSTALLED_APPS/DATABASES/MIDDLEWARE produces the specified behavior inside MTV architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | manage.py commands produces the specified behavior inside MTV architecture | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | path()/re_path()/include() produces the specified behavior inside URL routing & views | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | URL namespacing with app_name produces the specified behavior inside URL routing & views | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | FBV request object anatomy produces the specified behavior inside URL routing & views | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | CBV: TemplateView/ListView/DetailView/CreateView produces the specified behavior inside URL routing & views | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.5 | LoginRequiredMixin/PermissionRequiredMixin produces the specified behavior inside URL routing & views | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | variables/tags/filters produces the specified behavior inside Templates & context | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | {% extends %}/{% block %}/{% include %} produces the specified behavior inside Templates & context | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | custom template tags produces the specified behavior inside Templates & context | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | context processors produces the specified behavior inside Templates & context | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.1 | Form vs ModelForm produces the specified behavior inside Forms & validation | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.2 | clean_fieldname() and clean() produces the specified behavior inside Forms & validation | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.3 | CSRF protection produces the specified behavior inside Forms & validation | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.1 | list_display/list_filter/search_fields produces the specified behavior inside Admin panel | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.2 | custom admin actions produces the specified behavior inside Admin panel | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.3 | TabularInline/StackedInline produces the specified behavior inside Admin panel | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-6.1 | RedirectView and FormView produces the specified behavior inside Generic view reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-6.2 | UpdateView and DeleteView produces the specified behavior inside Generic view reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-6.3 | date-based generic views produces the specified behavior inside Generic view reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-6.4 | get_queryset/get_context_data/form_valid hooks produces the specified behavior inside Generic view reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1project/2├── manage.py3├── config/{settings,urls,asgi,celery}.py4├── domain/5│ ├── models.py6│ ├── services.py7│ ├── selectors.py8│ ├── serializers-or-schema.py9│ ├── views-or-resolvers.py10│ ├── permissions.py11│ ├── tasks.py12│ └── consumers.py13├── templates/14├── tests/{unit,api,integration}/15├── pyproject.toml16└── compose.yamlBuild plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | MTV architecture | Model-Template-View vs MVC; project vs app distinction; settings.py: INSTALLED_APPS/DATABASES/MIDDLEWARE | Demonstration plus focused tests |
| 2 | URL routing & views | path()/re_path()/include(); URL namespacing with app_name; FBV request object anatomy | Demonstration plus focused tests |
| 3 | Templates & context | variables/tags/filters; {% extends %}/{% block %}/{% include %}; custom template tags | Demonstration plus focused tests |
| 4 | Forms & validation | Form vs ModelForm; clean_fieldname() and clean(); CSRF protection | Demonstration plus focused tests |
| 5 | Admin panel | list_display/list_filter/search_fields; custom admin actions; TabularInline/StackedInline | Demonstration plus focused tests |
| 6 | Generic view reference | RedirectView and FormView; UpdateView and DeleteView; date-based generic views | Demonstration plus focused tests |
| 7 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1# blog/urls.py2from django.urls import path3from .views import PostDetail, PostList4
5app_name = "blog"6urlpatterns = [7 path("", PostList.as_view(), name="post-list"),8 path("<slug:slug>/", PostDetail.as_view(), name="post-detail"),9]10
11# blog/views.py12from django.views.generic import DetailView, ListView13from .models import Post14
15class PostList(ListView):16 queryset = Post.objects.filter(status="published").select_related("author")17 paginate_by = 2018
19class PostDetail(DetailView):20 queryset = Post.objects.filter(status="published").select_related("author")21 slug_field = "slug"Expected result
1GET /blog/ resolves PostList; GET /blog/a-slug/ resolves one published PostDetail.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | # blog/urls.py | Implements the next python statement in the example's data flow. |
| 2 | from django.urls import path | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 3 | from .views import PostDetail, PostList | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 5 | app_name = "blog" | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 6 | urlpatterns = [ | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 7 | path("", PostList.as_view(), name="post-list"), | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 8 | path(" | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 9 | ] | Implements the next python statement in the example's data flow. |
| 11 | # blog/views.py | Implements the next python statement in the example's data flow. |
| 12 | from django.views.generic import DetailView, ListView | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 13 | from .models import Post | Imports the named dependency; import executes the module once per interpreter cache and binds selected names here. |
| 15 | class PostList(ListView): | Creates a class namespace and binds the resulting class object to this name. |
| 16 | queryset = Post.objects.filter(status="published").select_related("author") | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 17 | paginate_by = 20 | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 19 | class PostDetail(DetailView): | Creates a class namespace and binds the resulting class object to this name. |
| 20 | queryset = Post.objects.filter(status="published").select_related("author") | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 21 | slug_field = "slug" | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| MTV architecture | Import-time database work and circular app imports make startup fragile. | Keep settings environment-driven and apps cohesive. |
| URL routing & views | Place access-control mixins before generic view bases and avoid overly clever inheritance chains. | Name every public route and reverse it instead of hard-coding URLs. |
| Templates & context | Only mark content safe after trusted sanitization; auto-escaping is a security boundary. | Keep queries and business rules out of templates. |
| Forms & validation | Client validation and serializer validation do not replace database constraints. | Enforce invariants again at the model/database boundary when concurrent writes matter. |
| Admin panel | Treat admin as privileged production software, not as an automatically safe public UI. | Optimize get_queryset for relation-heavy list pages and restrict powerful actions. |
| Generic view reference | get() requires exactly one row; only/defer can create surprise follow-up queries. | Push filtering and projection to SQL while keeping queries observable. |
Engineering checklist for this stack
- To do: authenticate before object lookup where possible
- To do: authorize the action and object server-side
- To do: keep transactions in the application service
- To do: bound request, response, and query work
- To do: map typed domain failures to stable protocol errors
Test strategy
Implement at least 12 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 4 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1def test_list_is_authorized_and_query_bounded(api_client, member, project, django_assert_num_queries):2 api_client.force_authenticate(member)3 with django_assert_num_queries(3):4 response = api_client.get("/api/resources/")5 assert response.status_code == 2006 assert all(item["project_id"] == str(project.id) for item in response.data["results"])Failure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?