Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow extra indexes to be specified, including multi-column &

unique
  • Loading branch information...
commit 1b6a505ea43237de3ba93f80cb683b69658a2b5e 1 parent 06e8cb9
@coleifer authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 peewee.py
View
14 peewee.py
@@ -2479,6 +2479,7 @@ def class_prepared(self):
class BaseModelOptions(object):
+ indexes = None
ordering = None
pk_sequence = None
@@ -2551,7 +2552,7 @@ def rel_exists(self, model):
class BaseModel(type):
- inheritable_options = ['database', 'ordering', 'pk_sequence']
+ inheritable_options = ['database', 'indexes', 'ordering', 'pk_sequence']
def __new__(cls, name, bases, attrs):
cls = super(BaseModel, cls).__new__(cls, name, bases, attrs)
@@ -2684,13 +2685,18 @@ def create_table(cls, fail_silently=False, extra=''):
if fail_silently and cls.table_exists():
return
- cls._meta.database.create_table(cls, extra=extra)
+ db = cls._meta.database
+ db.create_table(cls, extra=extra)
for field_name, field_obj in cls._meta.fields.items():
if isinstance(field_obj, ForeignKeyField):
- cls._meta.database.create_foreign_key(cls, field_obj)
+ db.create_foreign_key(cls, field_obj)
elif field_obj.db_index or field_obj.unique:
- cls._meta.database.create_index(cls, field_obj.name, field_obj.unique)
+ db.create_index(cls, field_obj.name, field_obj.unique)
+
+ if cls._meta.indexes:
+ for fields, unique in cls._meta.indexes:
+ db.create_index(cls, fields, unique)
@classmethod
def drop_table(cls, fail_silently=False):
Please sign in to comment.
Something went wrong with that request. Please try again.