This is a Django REST Framework (DRF) project that manages contacts and their associated phone numbers. It supports full CRUD functionality, nested serialization, validation, and filtering.
git clone https://github.com/mnpenchev/unilink-contacts-api.git cd unilink-contacts-api To open directly in Gitpod: https://gitpod.io/#https://github.com/mnpenchev/unilink-contacts-api
pip install -r requirements.txt
python manage.py makemigrations python manage.py migrate python manage.py runserver 0.0.0.0:8000
Then open the browser to: http://localhost:8000/api/contacts/
python manage.py test
- GET: List all contacts, including their phone numbers
- POST: Create a new contact with optional nested phone numbers
- Supports filtering by email and phone number via query params:
?email=example@example.com?phone=1234567890
- GET: Retrieve a single contact with phone numbers
- PUT: Update a contact and replace phone numbers
- DELETE: Delete a contact and all its phone numbers
- GET: List all phone numbers
- POST: Create a phone number (requires a
contactID)
- Contacts and phone numbers are modeled as separate entities with a foreign key relationship.
- Each contact can have at most one phone number of each type (mobile, work, home). This is enforced both at the serializer level and database level using a unique constraint.
- Two serializers are used for
PhoneNumber:- One for nested use inside the
ContactSerializer, wherecontactis injected automatically. - One standalone for the
/api/phone-numbers/endpoint, wherecontactis required.
- One for nested use inside the
- DRF’s
ModelViewSetis used to reduce boilerplate and make the code easier to extend. - Filtering is implemented using
django-filterto allow searching by phone number or email.
- The Contact model is named
Contactfor clarity even though the spec refers toTestContact. - Routes use
/api/contacts/as per REST naming conventions. - Gitpod users may need to manually expose port 8000 in the workspace UI.