self.json_data = json_da for k, v in json_data.items(): setattr(self, k, v) @classmethod def get(cls, resource_id): """ Returns an object of current Model requesting data to SWAPI using the api_client. """ # example-> luke = People.get(1) #result = api_client._call_swapi("%s/%s/%s" % (BASE_URL, if RESOURCE_NAME = #return api_client.get_people(resource_id) #if isinstance(cls, People): self.json_data = api_client.get_people(resource_id) #if isinstance(cls, Films): #self.json_data = api_client.get_films(resource_id) @classmethod def all(cls): """ Returns an iterable QuerySet of current Model. The QuerySet will be later in charge of performing requests to SWAPI for each of the pages while looping. """ if isinstance(cls, People): result = api_client.get_people() if isinstance(cls, Films):
super(PeopleQuerySet, self).__init__() def __repr__(self): return 'PeopleQuerySet: {0} objects'.format(str(len(self.objects))) class FilmsQuerySet(BaseQuerySet): RESOURCE_NAME = 'films' def __init__(self): super(FilmsQuerySet, self).__init__() def __repr__(self): return 'FilmsQuerySet: {0} objects'.format(str(len(self.objects))) json_data = api_client.get_people(1) class test(object): def __init__(self, json_data): """ Dynamically assign all attributes in `json_data` as instance attributes of the Model. """ self.json_data = json_data for k, v in json_data.items(): setattr(self, k, v) @classmethod def get(cls, resource_id): """ Returns an object of current Model requesting data to SWAPI using the api_client.