old_contents: # -*- coding: utf-8 -*-
  
  """
  byceps.blueprints.party.models
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
  :Copyright: 2006-2015 Jochen Kupperschmidt
  """
  
  from datetime import datetime
  
  from sqlalchemy.ext.hybrid import hybrid_property
  
  from ...database import db
  from ...util.datetime import DateTimeRange
  from ...util.instances import ReprBuilder
  
  from ..brand.models import Brand
  
  
  class Party(db.Model):
      """A party."""
      __tablename__ = 'parties'
  
      id = db.Column(db.Unicode(40), primary_key=True)
      brand_id = db.Column(db.Unicode(20), db.ForeignKey('brands.id'), index=True, nullable=False)
      brand = db.relationship(Brand, backref='parties')
      number = db.Column(db.Integer, nullable=False)
      title = db.Column(db.Unicode(40), unique=True, nullable=False)
      starts_at = db.Column(db.DateTime, nullable=False)
      ends_at = db.Column(db.DateTime, nullable=False)
      is_archived = db.Column(db.Boolean, default=False, nullable=False)
  
      @hybrid_property
      def range(self):
          return DateTimeRange(self.starts_at, self.ends_at)
  
      @property
      def is_over(self):
          """Returns true if the party has ended."""
          return self.ends_at < datetime.now()
  
      def __repr__(self):
          return ReprBuilder(self) \
              .add_with_lookup('id') \
              .add_with_lookup('title') \
              .build()
  
new_contents: # -*- coding: utf-8 -*-
  
  """
  byceps.blueprints.party.models
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
  :Copyright: 2006-2015 Jochen Kupperschmidt
  """
  
  from datetime import datetime
  
  from sqlalchemy.ext.hybrid import hybrid_property
  
  from ...database import db
  from ...util.datetime import DateTimeRange
  from ...util.instances import ReprBuilder
  
  from ..brand.models import Brand
  
  
  class Party(db.Model):
      """A party."""
      __tablename__ = 'parties'
      __table_args__ = (
          db.UniqueConstraint('brand_id', 'number'),
      )
  
      id = db.Column(db.Unicode(40), primary_key=True)
      brand_id = db.Column(db.Unicode(20), db.ForeignKey('brands.id'), index=True, nullable=False)
      brand = db.relationship(Brand, backref='parties')
      number = db.Column(db.Integer, nullable=False)
      title = db.Column(db.Unicode(40), unique=True, nullable=False)
      starts_at = db.Column(db.DateTime, nullable=False)
      ends_at = db.Column(db.DateTime, nullable=False)
      is_archived = db.Column(db.Boolean, default=False, nullable=False)
  
      @hybrid_property
      def range(self):
          return DateTimeRange(self.starts_at, self.ends_at)
  
      @property
      def is_over(self):
          """Returns true if the party has ended."""
          return self.ends_at < datetime.now()
  
      def __repr__(self):
          return ReprBuilder(self) \
              .add_with_lookup('id') \
              .add_with_lookup('title') \
              .build()
  
subject: Allow every party number only once per brand.