class Group(models.Model):
    """
    Tree-like structure that holds groups that may have other groups as leaves. 
    For example ``st01gp01`` is part of ``stage1``.
    This allows subgroups to work. The name is ``parents``, i.e.::
        >>> stage1group01 = Group.objects.get(unique_name = 'St 1 Gp01')
        >>> stage1group01
        >>> <Group: St 1 Gp01>
        >>> stage1group01.parents.all()
        >>> [<Group: Stage 1>]
    ``symmetrical`` on ``subgroup`` is needed to allow the 'parents' attribute to be 'visible'.
    """
subgroup = models.ManyToManyField('Group', related_name='parents',
    symmetrical=False, blank=True)
unique_name = models.CharField(max_length=255)
name = models.CharField(max_length=255)
academic_year = models.CharField(max_length=255)
dept_id = models.CharField(max_length=255)


class Meta:
    db_table = 'timetable_group'

def __unicode__(self):
    return '%s' % self.name
Django ease of building a RESTful interface