openbackloggery/collection/games/signals.py
Olivier DOSSMANN 242b0edff0 Refonte de la base:
* utilisation de classes abstraites Django : Item et Collection
  * héritage de ces classes pour Game et Console
  * création d'un objet Timeline contenant le changement d'état des jeux
  * affichage de la Timeline sur l'interface Admin
2017-08-22 21:02:43 +02:00

23 lines
702 B
Python

from games.models import Timeline
def game_saved(sender, instance, created, raw, using, update_fields,
**kwargs):
"""
Add timeline entry.
If game is created, add 2 timlines: 1 with CREATED status. The other with
current object status.
"""
# FIXME: don't write a timeline if previous have same title and object_id
entry = {
'item': instance,
'status': instance.status,
}
# Add CREATED status if Game was created
if created is True:
new_entry = dict(entry)
new_entry.update({'status': instance.CREATED})
Timeline.objects.create(**new_entry)
# Add new timeline entry
Timeline.objects.create(**entry)