Browse Source

fix coerce types

baz 4 years ago
parent
commit
c31066cb00
2 changed files with 8 additions and 7 deletions
  1. 3 2
      rxmap/rxmapp/models.py
  2. 5 5
      rxmap/rxmapp/views.py

+ 3 - 2
rxmap/rxmapp/models.py

@@ -42,7 +42,8 @@ class RapportoRicezione(models.Model):
 
     @property
     def colore(self):
-        c = self.comprensibile
+        c = int(self.comprensibile)
+        print(repr(c))
         if c > 3:
             return "green"
         if c > 1:
@@ -51,7 +52,7 @@ class RapportoRicezione(models.Model):
 
     @property
     def radius(self):
-        return self.stabilita * 70
+        return int(self.stabilita) * 70
 
     @property
     def explaination(self):

+ 5 - 5
rxmap/rxmapp/views.py

@@ -27,15 +27,15 @@ def rapporto_add(request):
     user = User.objects.filter(is_superuser=True).first()
     r = RapportoRicezione(
         author=user,
-        lat=request.POST["lat"],
-        lng=request.POST["lng"],
-        comprensibile=request.POST["comprensibile"],
-        stabilita=request.POST["comprensibile"],
+        lat=float(request.POST["lat"]),
+        lng=float(request.POST["lng"]),
+        comprensibile=int(request.POST["comprensibile"]),
+        stabilita=int(request.POST["comprensibile"]),
         tipo_radio=TipoRadio.objects.get(pk=request.POST["tiporadio"]),
     )
     r.save()
 
-    return JsonResponse(True, safe=False)
+    return JsonResponse(r.serialize())
 
 
 @csrf_exempt