The current API endpoint only returns the first available IP.
I thought we were going to create a new IP model instance as well, because that's what we need in some cases.
Therefore, in order to achieve what we need in some cases, we should do the following:
let's rename what you have done until now to get-first-available-ip (API) and get_first_available_ip() method
use GET for the API endpoint of get-first-available-ip because since it doesn't create anything it's idempotent
create a new method request_ip, which uses get_first_available_ip but then creates a new instance of ip address and returns it
create a new POST API endpoint for request_ip, this time using a DRF Serializer for the IpAddress model, try to use CreateApiView, you will need to override the post method to get the current subnet (or 404) and maybe also the create method
You can do this before or after having implemented the admin change you are working on right now.
The current API endpoint only returns the first available IP.
I thought we were going to create a new IP model instance as well, because that's what we need in some cases.
Therefore, in order to achieve what we need in some cases, we should do the following:
get-first-available-ip
(API) andget_first_available_ip()
methodGET
for the API endpoint ofget-first-available-ip
because since it doesn't create anything it's idempotentrequest_ip
, which usesget_first_available_ip
but then creates a new instance of ip address and returns itPOST
API endpoint forrequest_ip
, this time using a DRF Serializer for the IpAddress model, try to use CreateApiView, you will need to override thepost
method to get the current subnet (or 404) and maybe also thecreate
methodYou can do this before or after having implemented the admin change you are working on right now.