def creates(creates_list, whitelist=None): if not has_permission("creates"): return Exception("Creates not allowed") if not creates_list: return list() responses = list() for data in creates_list: model = app_utils.find_model_class(data.pop("_model"), whitelist=whitelist) instance = model.objects.create(**data) responses.append(instance.pk) return responses
def deletes(deletes_list, whitelist=None): if not has_permission("deletes"): raise Exception("Deletes not allowed") if not deletes_list: return list() responses = list() for data in deletes_list: model = app_utils.find_model_class(data.pop("_model"), whitelist=whitelist) cnt = model.objects.filter(pk=data.pop("_pk")).delete() responses.append(cnt) return responses
def updates(updates_list, whitelist=None): if not has_permission("updates"): raise Exception("Updates not allowed") if not updates_list: return [] responses = [] for data in updates_list: model = app_utils.find_model_class(data.pop("_model"), whitelist=whitelist) cnt = model.objects.filter(pk=data.pop("_pk")).update(**data) responses.append(cnt) return responses
def get_fields(request, modelname): model = find_model_class(modelname, whitelist=wl()) d = get_model_details(model, connections["default"]) return JsonResponse(d)
def test_find_model_class(self): self.assertEqual(find_model_class("Book"), Book)