Simple Django project prepared for recruitment process.
Please clone this clean repository into your workspace, do some work and create a pull request.
- Python 3.7
- pipenv (https://github.com/pypa/pipenv)
Execute in project's root directory:
pipenv sync
Since now you can switch to virtual environment created by pipenv. To do so run pipenv shell
command.
Otherwise you would have to add pipenv run
prefix to every python-related command executed
within project's directory tree (see below).
Execute in project's root directory:
pipenv run python manage.py migrate
pipenv run python manage.py createsuperuser
or
pipenv shell
./manage.py migrate
./manage.py createsuperuser
Execute in project's root directory:
pipenv shell
./manage.py runserver
Please run a linter before pushing to the repo. To do so simply execute:
pipenv run flake8
...add fix any issues.
The goal of the exercise is to create a system that tracks various events like clicks, page views, etc. Please complete the following tasks in a given order. Preferably you should prepare a separate commit for every task.
- Create
analytics.models.Event
model with given fields:name
- required non-empty string, maximum length equal to 255 characters,created_at
- required date of creation, automatically set to "now",additional_data
- optional text.
- Add
Event
model to the Django Admin panel. - In admin panel: make
Event
model searchable byname
. - Add REST endpoint
POST /api/events
that allows to create anEvent
with givenname
andadditional_data
. Implement any validations, views, forms and serializers needed. It's up to you. Remember about tests. - Extend existing
User
model (django.contrib.auth.models.User
) with new field:api_token
- optional string, maximum length equal to 100, unique.
- Extend existing
Event
model (analytics.models.Event
) with new field:created_by
- required foreign key pointing toUser
- Update
POST /api/events
endpoint. From now on it should check theAuthorization
HTTP Header of every incoming request. In case of missing or invalidAuthorization
header it should return an error with HTTP Code401 Unauthorized
. ValidAuthorization
header looks like this:Authorization: Bearer API_TOKEN
, whereAPI_TOKEN
is an existingapi_token
provided for any existingUser
(see point 5). Newly created event'screated_by
field should be set toUser
whoseAPI_TOKEN
has been provided in theAuthorization
header. Remember about tests. - In Admin panel: make
Event
searchable bycreated_by.username
in addition toname
implemeted in point 3.
Extending User
model can be tricky. You are allowed to prepare your own User
model based on django.contrib.auth.models.AbstractUser
and override AUTH_USER_MODEL
. You can also create a separate model for API Tokens
and link to existing users. It's up to you.
Optional things to consider:
- Djagno REST Framework (https://github.com/encode/django-rest-framework),
- Move
Authorization: Bearer API_TOKEN
evaluation to middleware.