Created
March 19, 2018 08:44
-
-
Save shulcsm/081b3b08778444a9af978596df8b5bce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IUniqueIndex(models.Index): | |
suffix = 'iuq' | |
sql_template = 'CREATE UNIQUE INDEX %(name)s ON %(table)s (%(columns)s);' | |
def create_sql(self, model, schema_editor, using=''): | |
assert schema_editor.connection.vendor == 'postgresql' | |
fields = [model._meta.get_field(field_name) for field_name, _ in self.fields_orders] | |
quote_name = schema_editor.quote_name | |
return self.sql_template % ({ | |
'name': quote_name(self.name), | |
'table': quote_name(model._meta.db_table), | |
'columns': ", ".join(['UPPER(%s)' % quote_name(field.column) for field in fields]) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment