forked from Minecraft/minecraft_manager
parent
e1696d3f5f
commit
e052646542
27
api/views.py
27
api/views.py
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue