# Path: boardinghouse/models.py
# class AbstractSchema(SharedSchemaMixin, models.Model):
#     """
#     The Schema model provides an abstraction for a Postgres schema.
# 
#     It will take care of creating a cloned copy of the template_schema
#     when it is created, and also has the ability to activate and deactivate
#     itself (at the start and end of the request cycle would be a good plan).
#     """
# 
#     schema = models.CharField(
#         max_length=36, primary_key=True, unique=True,
#         validators=[schema_name_validator],
#         help_text='<br>'.join([
#             u'The internal name of the schema.',
#             SCHEMA_NAME_VALIDATOR_MESSAGE,
#             u'May not be changed after creation.',
#         ]),
#     )
#     name = models.CharField(
#         max_length=128, unique=True,
#         help_text=_(u'The display name of the schema.')
#     )
#     is_active = models.BooleanField(
#         default=True,
#         help_text=_(u'Use this instead of deleting schemata.')
#     )
# 
#     objects = SchemaQuerySet.as_manager()
# 
#     class Meta:
#         abstract = True
# 
#     def __init__(self, *args, **kwargs):
#         super(AbstractSchema, self).__init__(*args, **kwargs)
#         self._initial_schema = self.schema
# 
#     def __str__(self):
#         return '{0} ({1})'.format(self.name, self.schema)
# 
#     def save(self, *args, **kwargs):
#         self._meta.get_field('schema').run_validators(self.schema)
# 
#         # We want to prevent someone creating a new schema with
#         # the same internal name as an existing one. We assume that
#         # if we haven't been saved, then there should not be a
#         # schema in the database with this name.
#         if self._initial_schema in [None, ''] or 'force_insert' in kwargs:
#             if _schema_exists(self.schema):
#                 raise ValidationError(_('Schema %s already in use') % self.schema)
#         elif self.schema != self._initial_schema:
#             raise ValidationError(_('may not change schema after creation.'))
# 
#         return super(AbstractSchema, self).save(*args, **kwargs)
# 
#     def delete(self, drop=False):
#         if drop:
#             super(AbstractSchema, self).delete()
#         else:
#             self.is_active = False
#             self.save()
# 
#     def activate(self, cursor=None):
#         activate_schema(self.schema)
# 
#     @classmethod
#     def deactivate(cls, cursor=None):
#         deactivate_schema()


from django.db import models
from django.conf import settings
from django.utils.translation import ugettext as _
from boardinghouse.models import AbstractSchema

class Subject(models.Model):
    name = models.CharField(unique=True, max_length=64)

    def __str__(self):
        return self.name

SEMESTERS = (
    (0, 'Summer Semester'),
    (1, 'Semester 1'),
    (2, 'Semester 2'),
)

GRADES = (
    ('HD', 'High Distinction'),
    ('D', 'Distinction'),
    ('C', 'Credit'),
    ('P1', 'Pass, Level 1'),
    ('P2', 'Pass, Level 2'),
    ('F1', 'Fail, Level 1'),
    ('F2', 'Fail, Level 2'),
    ('NGP', 'Non-Graded Pass'),
    ('NGF', 'Non-Graded Fail'),
)


class Enrolment(models.Model):
    student = models.ForeignKey(Student, related_name='enrolments')
    subject = models.ForeignKey(Subject, related_name='enrolments')
    enrolment_date = models.DateField()

# Path: boardinghouse/models.py
# class AbstractSchema(SharedSchemaMixin, models.Model):
#     """
#     The Schema model provides an abstraction for a Postgres schema.
# 
#     It will take care of creating a cloned copy of the template_schema
#     when it is created, and also has the ability to activate and deactivate
#     itself (at the start and end of the request cycle would be a good plan).
#     """
# 
#     schema = models.CharField(
#         max_length=36, primary_key=True, unique=True,
#         validators=[schema_name_validator],
#         help_text='<br>'.join([
#             u'The internal name of the schema.',
#             SCHEMA_NAME_VALIDATOR_MESSAGE,
#             u'May not be changed after creation.',
#         ]),
#     )
#     name = models.CharField(
#         max_length=128, unique=True,
#         help_text=_(u'The display name of the schema.')
#     )
#     is_active = models.BooleanField(
#         default=True,
#         help_text=_(u'Use this instead of deleting schemata.')
#     )
# 
#     objects = SchemaQuerySet.as_manager()
# 
#     class Meta:
#         abstract = True
# 
#     def __init__(self, *args, **kwargs):
#         super(AbstractSchema, self).__init__(*args, **kwargs)
#         self._initial_schema = self.schema
# 
#     def __str__(self):
#         return '{0} ({1})'.format(self.name, self.schema)
# 
#     def save(self, *args, **kwargs):
#         self._meta.get_field('schema').run_validators(self.schema)
# 
#         # We want to prevent someone creating a new schema with
#         # the same internal name as an existing one. We assume that
#         # if we haven't been saved, then there should not be a
#         # schema in the database with this name.
#         if self._initial_schema in [None, ''] or 'force_insert' in kwargs:
#             if _schema_exists(self.schema):
#                 raise ValidationError(_('Schema %s already in use') % self.schema)
#         elif self.schema != self._initial_schema:
#             raise ValidationError(_('may not change schema after creation.'))
# 
#         return super(AbstractSchema, self).save(*args, **kwargs)
# 
#     def delete(self, drop=False):
#         if drop:
#             super(AbstractSchema, self).delete()
#         else:
#             self.is_active = False
#             self.save()
# 
#     def activate(self, cursor=None):
#         activate_schema(self.schema)
# 
#     @classmethod
#     def deactivate(cls, cursor=None):
#         deactivate_schema()


# Path: examples/boarding_school/school/models.py
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext as _
from boardinghouse.models import AbstractSchema


class Subject(models.Model):
    name = models.CharField(unique=True, max_length=64)

    def __str__(self):
        return self.name

SEMESTERS = (
    (0, 'Summer Semester'),
    (1, 'Semester 1'),
    (2, 'Semester 2'),
)

GRADES = (
    ('HD', 'High Distinction'),
    ('D', 'Distinction'),
    ('C', 'Credit'),
    ('P1', 'Pass, Level 1'),
    ('P2', 'Pass, Level 2'),
    ('F1', 'Fail, Level 1'),
    ('F2', 'Fail, Level 2'),
    ('NGP', 'Non-Graded Pass'),
    ('NGF', 'Non-Graded Fail'),
)


class Enrolment(models.Model):
    student = models.ForeignKey(Student, related_name='enrolments')
    subject = models.ForeignKey(Subject, related_name='enrolments')
    enrolment_date = models.DateField()

    year = models.IntegerField()