[Answer]-Django – HttpResponse for already full

1👍

You should raise a custom exception for full busses

from rest_framework.exceptions import APIException

class FullBusException(APIException):
    status_code = 409
    default_detail = 'This bus is already full.'

Then in your view code import and raise this exception if the bus is already full when the user tries to add themselves to it. Django rest framework will then deal with handling the exception.

http://www.django-rest-framework.org/api-guide/exceptions/

Leave a comment