A single cumulative Django project (turn-in directory ex/) implementing the
whole "Sessions" day, ex00 → ex06. Each exercise builds on the previous one, so
the final project is the most advanced state and covers all of them.
Generated with lsphere.
- Python 3 / Django 5.2 LTS
django-bootstrap5for form rendering and styling- SQLite database
- Custom user model
tips.User(set from the start soAUTH_USER_MODELis correct before the first migration)
docker compose up --build
# open http://localhost:8000The container runs entrypoint.sh, which builds and applies migrations and
creates a default superuser admin / adminadmin for the admin interface.
Useful commands:
docker compose exec web python ex/manage.py createsuperuser
docker compose exec web python ex/manage.py shell- ex00 – Anonymous sessions:
tips/context_processors.py:anonymous_namepicks one ofsettings.RANDOM_NAMES(10 names), stored in the session with asettings.RANDOM_NAME_VALIDITY(42 s) expiry. Computed and shown within the same request, so it appears instantly. Displayed in the<nav>as "Hello !". - ex01 – User creation:
RegisterForm(username + 2 password fields, validates uniqueness and matching passwords) andLoginForm(AuthenticationForm). Logged-in users are redirected away from the register/login pages; nav swaps to the username + a logout link. - ex02 – Tips:
Tipmodel (content,author,date) and theTipFormModelForm, shown on the homepage only to logged-in users. - ex03 – Votes:
Tip.upvotes/Tip.downvotesManyToMany fields (no counters). Voting toggles, is mutually exclusive, and each action reloads the page (POST → redirect). Counts derived from the relations. - ex04 – Authorizations (delete): uses the default
tips.delete_tippermission; the admin interface is enabled. The tip's author is always allowed (the only exception). - ex05 – Personalized authorization (downvote): custom permission
tips.can_downvote(declared inTip.Meta.permissions) restrains downvoting; authors can always downvote their own tips. - ex06 – Reputation: the custom
Userexposes areputationproperty computed from the votes on the user's tips (+5 per upvote, −2 per downvote; deleting a tip removes its influence automatically).can_downvote()unlocks at 15 rep andcan_delete_tips()at 30 rep (also satisfied by the permissions above / superuser). The username is shown with its reputation in brackets, e.g.alice [15].
Migrations and db.sqlite3 are git-ignored and regenerated on container start,
as the evaluation does.