Spotifake es un proyecto de ejemplo que usa Django y Django REST Framework.
La aplicación funciona como una versión simplificada de Spotify. Permite crear artistas y álbumes con pistas. Hay una explicación en el siguiente video.
Se adjunta una colección de Postman en el archivo spotifake.postman_collection.json.
Existen tres modelos: Artist, Album y Track. Cada Album pertenece a un Artist. Cada Track pertenece a un Album y un Artist y además puede tener otros Artist como colaboradores.
Se usan ModelSerializer para cada modelo. En serializers.py hay ejemplos de custom fields, campos dinámicos, campos anidados y creación de objetos con campos anidados.
Se usan Generic Views con algunas implementaciones personalizadas de get_queryset
para filtrar los resultados de Album y Track según el tipo de usuario y la fecha de publicación del Album.
En permissions.py hay una implementación de IsAdminOrReadOnly, que permite operaciones de escritura solo a usuarios administradores.
Como una solución a la vulnerabilidad descrita en http:https://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx/, se usa un Renderer personalizado que envuelve en un diccionario todas las respuestas que tienen como raíz una lista. El nombre de la llave que contiene la lista se define en el serializer.
Se incluye una base de datos sqlite3 pre-cargada con el usuario administrador admin
(password asdasdasd
), dos artistas, un álbum y dos pistas.
Spotifake is a sample project made with Django and Django REST Framework.
The app works as a very simplified version of Spotify. It allows to create artists, albums and tracks.
There is a Postman collection with the API specs in spotifake.postman_collection.json.
There are three models: Artist, Album and Track. Each Album belongs to an Artist. Each Track belongs to an Album and and Artist. Tracks can also have other Artists as collaborators.
There is a ModelSerializer for each model. In serializers.py there are uses of custom fields, dynamic fields, nested fields and creation of objects with nested fields.
There are some Generic Views with customized implementations of get_queryset
to filter results by Album and Track depending on the user privileges and the release date of the album.
In permissions.py there is an implementation of IsAdminOrReadOnly
, which allows write operations only to administrators.
To prevent attacks as described in http:https://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx/, a custom Renderer is used. It wraps every array response in a dictionary. The name of the key that will contain the array is defined in the serializer.
A preloaded sqlite3 database is included. It contains the admin user (U:admin
, P:asdasdasd
), two artists, one album and two tracks.