from django.db import models
from django.utils.translation import ugettext_lazy as _
from member.models import Person, Institution

# Defining the duration of a Training Program
ONE_HOUR = '1h'
ONE_AND_A_HALF_HOUR = '1h30'
TWO_HOURS = '2h'
TWO_AND_A_HALF_HOURS = '2h30'
THREE_HOURS = '3h'
THREE_AND_A_HALF_HOURS = '3h30'
FOUR_HOURS = '4h'
FOUR_AND_A_HALF_HOURS = '4h30'
FIVE_HOURS = '5h'
FIVE_AND_A_HALF_HOURS = '5h30'
SIX_HOURS = '6h'
SIX_AND_A_HALF_HOURS = '6h30'
SEVEN_HOURS = '7h'
SEVEN_AND_A_HALF_HOURS = '7h30'
EIGHT_HOURS = '8h'
EIGHT_AND_A_HALF_HOURS = '8h30'
NINE_HOURS = '9h'
NINE_AND_A_HALF_HOURS = '9h30'
TEN_HOURS = '10h'
OTHER = 'Other'
DURATION = (
    (ONE_HOUR, '1h'),
    (ONE_AND_A_HALF_HOUR, '1h30'),
    (TWO_HOURS, '2h'),
    (TWO_AND_A_HALF_HOURS, '2h30'),
    (THREE_HOURS, '3h'),
    (THREE_AND_A_HALF_HOURS, '3h30'),
    (FOUR_HOURS, '4h'),
    (FOUR_AND_A_HALF_HOURS, '4h30'),
    (FIVE_HOURS, '5h'),
    (FIVE_AND_A_HALF_HOURS, '5h30'),
    (SIX_HOURS, '6h'),
    (SIX_AND_A_HALF_HOURS, '6h30'),
    (SEVEN_HOURS, '7h'),
    (SEVEN_AND_A_HALF_HOURS, '7h30'),
    (EIGHT_HOURS, '8h'),
    (EIGHT_AND_A_HALF_HOURS, '8h30'),
    (NINE_HOURS, '9h'),
    (NINE_AND_A_HALF_HOURS, '9h30'),
    (TEN_HOURS, '10h'),
    (OTHER, _('Other duration time'))
)

# Defining types of activities
TRAINING_PROGRAM = 't'
MEETING = 'm'
SEMINAR = 's'
TYPE_OF_ACTIVITY = (
    (TRAINING_PROGRAM, _('Training Program')),
    (MEETING, _('Meeting')),
    (SEMINAR, _('Seminar')),
)


class ProjectActivities(models.Model):
    speaker = models.ManyToManyField(Person, verbose_name=_('Speaker'))
    institution = models.ForeignKey(Institution, verbose_name=_('Institution'), blank=True, null=True)
    type_of_activity = models.CharField(_('Type of activity'), max_length=1, choices=TYPE_OF_ACTIVITY, blank=True)


class TrainingProgram(ProjectActivities):
    """
    An instance of this class is a training program.

    """
    title = models.CharField(_('Title'), max_length=255)
    description = models.TextField(_('Description'), blank=True, null=True)
    start_date = models.DateField(_('Start date'))
    end_date = models.DateField(_('End date'), blank=True, null=True)
    duration = models.CharField(_('Duration'), max_length=5, choices=DURATION)
    other_duration = models.CharField(_('Other duration time'), max_length=5, blank=True, null=True,
                                      help_text='E.g.: 11h or 11h30')

    def __unicode__(self):
        return u'%s' % self.title

    class Meta:
        verbose_name = _('Training Program')
        verbose_name_plural = _('Training Programs')
        ordering = ('-start_date', )

    # Sets the type of activity as Training Program
    def save(self, *args, **kwargs):
        self.type_of_activity = TRAINING_PROGRAM
        super(TrainingProgram, self).save(*args, **kwargs)


class Seminar(ProjectActivities):
    """
    An instance of this class is a seminar.

    """
    title = models.CharField(_('Title'), max_length=255)
    abstract = models.TextField(_('Abstract'), blank=True, null=True)
    date = models.DateField(_('Date'))
    attachment = models.FileField(_('Attachment'), blank=True, null=True)

    def __unicode__(self):
        return u'%s' % self.title

    class Meta:
        verbose_name = _('Seminar')
        verbose_name_plural = _('Seminars')
        ordering = ('-date', )

    # Sets the type of activity as Seminar
    def save(self, *args, **kwargs):
        self.type_of_activity = SEMINAR
        super(Seminar, self).save(*args, **kwargs)


class Meeting(ProjectActivities):
    """
    An instance of this class is a meeting.

    """
    event_name = models.CharField(_('Event name'), max_length=255)
    cepid_event = models.BooleanField(_('CEPID event?'), default=False)
    participant = models.ManyToManyField(Person, verbose_name=_('Participant'), blank=True, null=True)
    description = models.TextField(_('Description'))
    start_date = models.DateField(_('Start date'))
    end_date = models.DateField(_('End date'))
    url = models.URLField(_('URL'), blank=True, null=True)
    seminar = models.ManyToManyField(Seminar, verbose_name=_('Seminars'), blank=True, null=True)
    training_program = models.ManyToManyField(TrainingProgram, verbose_name=_('Training Programs'), blank=True,
                                              null=True)

    def __unicode__(self):
        return u'%s' % self.event_name

    class Meta:
        verbose_name = _('Meeting')
        verbose_name_plural = _('Meetings')
        ordering = ('-start_date', )

    # Sets the type of activity as Meeting
    def save(self, *args, **kwargs):
        self.type_of_activity = MEETING
        super(Meeting, self).save(*args, **kwargs)
@@ -1811,16 +1811,356 @@
 =True)%0A%0A
+    def __unicode__(self):%0A        if self.type_of_activity == 't':%0A            return u'%25s' %25 TrainingProgram.objects.get(pk=self.pk)%0A        elif self.type_of_activity == 'm':%0A            return u'%25s' %25 Meeting.objects.get(pk=self.pk)%0A        elif self.type_of_activity == 's':%0A            return u'%25s' %25 Seminar.objects.get(pk=self.pk)%0A%0A
 %0Aclass T

Set __unicode__ to ProjectActivities class