'Trouble understanding the task of Django and Django rest framework?
Here I have trouble understanding the above question. I have a task given as above. It says I have to make an api (get api) in Django which contains the above four fields id, name, latitude and longitude. It is simple to make a get api, if I can save the data to the database from Django-admin. But here, I suppose it says to use google map apis. Ok, somehow I can get the data from the google apis ( I am not so sure which python package is best for this), but how to save that data to the db, and later show it while calling get api??
Solution 1:[1]
Introduce an interface:
interface Service {
void execute();
}
class Service1 implements Service { ... }
class Service2 implements Service { ... }
List<Service> serviceList = ...
for (Service service: serviceList) {
service.execute();
}
Solution 2:[2]
Firstly, ArrayList<T> only can accept the declared type T, so you cannot add objects of a different type, say K into the same ArrayList.
Solution 1
A solution for your need could be to declare ArrayList<Object> list and then add the two services.
Solution 2
Now, because you want a common execute method, it would be natural for your Service1 and Service2 classes to implement some interface, say Service to achieve a unique execute method implementation for each class. And you can declare your ArrayList as ArrayList<Service> list
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tgdavies |
| Solution 2 |

