def __init__(self, rest_api, model, authentication, allowed_methods=None): self.api = rest_api self.model = model self.pk = model._meta.primary_key self.authentication = authentication self.allowed_methods = allowed_methods or [ 'GET', 'POST', 'PUT', 'DELETE' ] self._fields = { self.model: self.fields or self.model._meta.sorted_field_names } if self.exclude: self._exclude = {self.model: self.exclude} else: self._exclude = {} self._filter_fields = self.filter_fields or list( self.model._meta.sorted_field_names) self._filter_exclude = self.filter_exclude or [] self._resources = {} # recurse into nested resources if self.include_resources: for field_name, resource in self.include_resources.items(): field_obj = self.model._meta.fields[field_name] resource_obj = resource(self.api, field_obj.rel_model, self.authentication, self.allowed_methods) self._resources[field_name] = resource_obj self._fields.update(resource_obj._fields) self._exclude.update(resource_obj._exclude) self._filter_fields.extend([ '%s__%s' % (field_name, ff) for ff in resource_obj._filter_fields ]) self._filter_exclude.extend([ '%s__%s' % (field_name, ff) for ff in resource_obj._filter_exclude ]) self._include_foreign_keys = False else: self._include_foreign_keys = True self._field_tree = make_field_tree(self.model, self._filter_fields, self._filter_exclude, self.filter_recursive)
def __init__(self, rest_api, model, authentication, allowed_methods=None, route=None): self.api = rest_api self.model = model self.pk = model._meta.primary_key self.authentication = authentication self.allowed_methods = allowed_methods or ['GET', 'POST', 'PUT', 'DELETE'] self.route = route or self.model.__name__ self._fields = {self.model: self.fields or self.model._meta.get_field_names()} if self.exclude: self._exclude = {self.model: self.exclude} else: self._exclude = {} self._filter_fields = self.filter_fields or self.model._meta.get_field_names() self._filter_exclude = self.filter_exclude or [] self._resources = {} # recurse into nested resources if self.include_resources: for field_name, resource in self.include_resources.items(): field_obj = self.model._meta.fields[field_name] resource_obj = resource(self.api, field_obj.rel_model, self.authentication, self.allowed_methods) self._resources[field_name] = resource_obj self._fields.update(resource_obj._fields) self._exclude.update(resource_obj._exclude) self._filter_fields.extend(['%s__%s' % (field_name, ff) for ff in resource_obj._filter_fields]) self._filter_exclude.extend(['%s__%s' % (field_name, ff) for ff in resource_obj._filter_exclude]) self._include_foreign_keys = False else: self._include_foreign_keys = True self._field_tree = make_field_tree(self.model, self._filter_fields, self._filter_exclude, self.filter_recursive)
def __init__(self, rest_api, model, authentication, allowed_methods=None): self.api = rest_api self.model = model self.authentication = authentication self.allowed_methods = allowed_methods or ["GET", "POST", "PUT", "DELETE"] self._operations = self.model._meta.database.adapter.operations self._fields = {self.model: self.fields or self.model._meta.get_field_names()} if self.exclude: self._exclude = {self.model: self.exclude} else: self._exclude = {} self._filter_fields = self.filter_fields or self.model._meta.get_field_names() self._filter_exclude = self.filter_exclude or [] self._resources = {} # recurse into nested resources if self.include_resources: for field_name, resource in self.include_resources.items(): field_obj = self.model._meta.fields[field_name] resource_obj = resource(self.api, field_obj.to, self.authentication, self.allowed_methods) self._resources[field_name] = resource_obj self._fields.update(resource_obj._fields) self._exclude.update(resource_obj._exclude) self._filter_fields.extend(["%s__%s" % (field_name, ff) for ff in resource_obj._filter_fields]) self._filter_exclude.extend(["%s__%s" % (field_name, ff) for ff in resource_obj._filter_exclude]) self._include_foreign_keys = False else: self._include_foreign_keys = True self._field_tree = make_field_tree(self.model, self._filter_fields, self._filter_exclude, self.filter_recursive)