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.Eventmodel 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
Eventmodel to the Django Admin panel. - In admin panel: make
Eventmodel searchable byname. - Add REST endpoint
POST /api/eventsthat allows to create anEventwith givennameandadditional_data. Implement any validations, views, forms and serializers needed. It's up to you. Remember about tests. - Extend existing
Usermodel (django.contrib.auth.models.User) with new field:api_token- optional string, maximum length equal to 100, unique.
- Extend existing
Eventmodel (analytics.models.Event) with new field:created_by- required foreign key pointing toUser
- Update
POST /api/eventsendpoint. From now on it should check theAuthorizationHTTP Header of every incoming request. In case of missing or invalidAuthorizationheader it should return an error with HTTP Code401 Unauthorized. ValidAuthorizationheader looks like this:Authorization: Bearer API_TOKEN, whereAPI_TOKENis an existingapi_tokenprovided for any existingUser(see point 5). Newly created event'screated_byfield should be set toUserwhoseAPI_TOKENhas been provided in theAuthorizationheader. Remember about tests. - In Admin panel: make
Eventsearchable bycreated_by.usernamein addition tonameimplemeted 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_TOKENevaluation to middleware.