Sto scrivendo un Django applicazione per tenere traccia di oggetti (Objekt) e la loro attività di manutenzione. Oggetti può essere collegato a una posizione.
Posizione (0/1) --- (n) Objekt (1) --- (n) Attività
Posizione, Objekt e Attività tutti hanno un campo di stato con i seguenti valori:
RED = "red"
YELLOW = "yellow"
GREEN = "green"
STATUS = [
(RED, "Overdue tasks"),
(YELLOW, "Pending tasks"),
(GREEN, "All good"),
]
Voglio che l'Ubicazione sulla mappa indicatore cambia colore in base allo stato dei relativi Oggetti e ultimatelly Attività.
Ho provato a seguire django migliori pratiche e crea un fat modello.
from django.db import models
from locationapp.models import Location
from taskapp.models import Task
from rules.contrib.models import RulesModel
class Objekt(RulesModel):
RED = "red"
YELLOW = "yellow"
GREEN = "green"
STATUS = [
(RED, "Overdue tasks"),
(YELLOW, "Pending tasks"),
(GREEN, "All good"),
]
name = models.CharField(max_length=200)
description = models.TextField(blank=True)
location = models.ForeignKey(
Location, on_delete=models.SET_NULL, null=True, blank=True
)
status = models.CharField(max_length=6, choices=STATUS, default=GREEN)
def set_status(self):
if Task.objects.filter(objekt=self.id).filter(status=Task.RED).exists():
self.status = Objekt.RED
elif Task.objects.filter(objekt=self.id).filter(status=Task.YELLOW).exists():
self.status = Objekt.YELLOW
else:
self.status = Objekt.GREEN
Ma in qualche modo io non sono sicuro del mio concetto... Come è possibile un aggiornamento sulle Attività di attivare un aggiornamento sulle relative Objekt. E come sarebbe il Objekt ulteriori attivare l'aggiornamento sulla Posizione - se richiesto a tutti?