Compare commits

...

1 Commits

Author SHA1 Message Date
Etzelia e052646542
Add model POST API
Signed-off-by: Etzelia <etzelia@hotmail.com>
2019-11-21 20:28:05 -06:00
1 changed files with 26 additions and 1 deletions

View File

@ -398,7 +398,32 @@ class ModelAPI(View):
return JsonResponse(json, safe=False) return JsonResponse(json, safe=False)
def post(self, request, request_model): def post(self, request, request_model):
pass json = {"success": False, "message": ""}
print(request.POST)
if request_allowed(request, 'model_post_permission'):
post = request.POST
model = None
for m in apps.get_app_config('minecraft_manager').get_models():
if m._meta.model_name.upper() == request_model.upper():
model = m
break
if model:
keywords = clean(model, post)
if "id" in keywords:
try:
obj = model.objects.get(id=keywords["id"])
for key in keywords.keys():
setattr(obj, key, keywords[key])
obj.save()
json["success"] = True
json["message"] = "Model updated"
except Exception as ex:
print(ex)
json["message"] = "Could not update model"
else:
json["message"] = "Must provide an ID"
return JsonResponse(json)
class StatsAPI(View): class StatsAPI(View):