23 lines
702 B
Python
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)
|