better integration of notes, templates clean up

This commit is contained in:
Arthur Gerbaud
2016-08-06 19:28:15 +02:00
parent b3ca132a73
commit aefeb2e349
12 changed files with 101 additions and 63 deletions

View File

@@ -1,6 +1,8 @@
from django.db import models
from django.utils.html import format_html
from . import managers
class Note(models.Model):
""" Note relative à un sujet.
@@ -13,6 +15,8 @@ class Note(models.Model):
"""
objects = managers.NoteManager()
sujet = models.ForeignKey(
'sujets.Sujet',
related_name="notes",
@@ -25,11 +29,12 @@ class Note(models.Model):
null=True
)
created_date = models.DateField('Crée le', blank=True, null=True)
created_time = models.TimeField('Heure', blank=True, null=True)
def save(self, *args, **kwargs):
if not self.created_date: # Retrieve from child class instance
self.created_date = self.cast().get_date()
child_instance = self.cast()
self.created_date = child_instance.note_date()
self.created_time = child_instance.note_time()
return super().save(*args, **kwargs)
def _get_child_class_and_instance(self):
@@ -68,7 +73,7 @@ class Note(models.Model):
setattr(self,
private_name,
# Call *child instance* method
getattr(self.cast(), 'get_%s' % name)()
getattr(self.cast(), 'note_%s' % name)()
)
return getattr(self, private_name)
return getter