aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
authorRodney Ewing <ewing.rj@gmail.com>2013-04-23 18:28:10 -0700
committerRodney Ewing <ewing.rj@gmail.com>2013-04-24 14:31:51 -0700
commit34d8bc9820a945ae6af07764d0ea3b058829fef1 (patch)
tree681fc3e8aa0aaf9312e5963d0f0d32637b24bcdc /mediagoblin/db/models.py
parentcec9648c11d851baa8add4f49cdcdbc5416386a9 (diff)
downloadmediagoblin-34d8bc9820a945ae6af07764d0ea3b058829fef1.tar.lz
mediagoblin-34d8bc9820a945ae6af07764d0ea3b058829fef1.tar.xz
mediagoblin-34d8bc9820a945ae6af07764d0ea3b058829fef1.zip
Check for duplicate collection slugs and make them unique. Add unique constraint to collection.slug model
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r--mediagoblin/db/models.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index fcfd0f61..2412706e 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -410,7 +410,7 @@ class Collection(Base, CollectionMixin):
title = Column(Unicode, nullable=False)
slug = Column(Unicode)
created = Column(DateTime, nullable=False, default=datetime.datetime.now,
- index=True)
+ index=True)
description = Column(UnicodeText)
creator = Column(Integer, ForeignKey(User.id), nullable=False)
# TODO: No of items in Collection. Badly named, can we migrate to num_items?
@@ -421,6 +421,10 @@ class Collection(Base, CollectionMixin):
backref=backref("collections",
cascade="all, delete-orphan"))
+ __table_args__ = (
+ UniqueConstraint('creator', 'slug'),
+ {})
+
def get_collection_items(self, ascending=False):
#TODO, is this still needed with self.collection_items being available?
order_col = CollectionItem.position