1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | from django.db.models.fields import (SmallIntegerField,
|
---|
4 | PositiveSmallIntegerField,
|
---|
5 | AutoField)
|
---|
6 |
|
---|
7 | from django.conf import settings
|
---|
8 |
|
---|
9 | class TinyIntegerField(SmallIntegerField):
|
---|
10 | def db_type(self, connection):
|
---|
11 | if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql':
|
---|
12 | return "tinyint"
|
---|
13 | else:
|
---|
14 | return super(TinyIntegerField, self).db_type(connection)
|
---|
15 |
|
---|
16 |
|
---|
17 | class PositiveTinyIntegerField(PositiveSmallIntegerField):
|
---|
18 | def db_type(self, connection):
|
---|
19 | if connection.settings_dict['ENGINE'] == 'django.db.backends.mysql':
|
---|
20 | return "tinyint unsigned"
|
---|
21 | else:
|
---|
22 | return super(PositiveTinyIntegerField, self).db_type(connection)
|
---|
23 |
|
---|
24 |
|
---|
25 | class PositiveSmallAutoField(AutoField):
|
---|
26 | def db_type(self):
|
---|
27 | if settings.DATABASE_ENGINE == 'mysql':
|
---|
28 | return "smallint unsigned AUTO_INCREMENT"
|
---|
29 | else:
|
---|
30 | return super(AutoField, self).db_type(connection)
|
---|
31 | def get_internal_type(self):
|
---|
32 | return "PositiveSmallAutoField"
|
---|
33 |
|
---|
34 |
|
---|
35 | class PositiveTinyAutoField(AutoField):
|
---|
36 | def db_type(self):
|
---|
37 | if settings.DATABASE_ENGINE == 'mysql':
|
---|
38 | return "tinyint unsigned AUTO_INCREMENT"
|
---|
39 | else:
|
---|
40 | return super(AutoField, self).db_type(connection)
|
---|
41 | def get_internal_type(self):
|
---|
42 | return "PositiveTinyAutoField"
|
---|
43 |
|
---|
44 |
|
---|
45 | from south.modelsinspector import add_introspection_rules
|
---|
46 | add_introspection_rules([], ["^liveview\.livedata\.custommodels\.PositiveTinyIntegerField"])
|
---|
47 | add_introspection_rules([], ["^liveview\.livedata\.custommodels\.TinyIntegerField"])
|
---|
48 | add_introspection_rules([], ["^liveview\.livedata\.custommodels\.PositiveSmallAutoField"])
|
---|
49 | add_introspection_rules([], ["^liveview\.livedata\.custommodels\.PositiveTinyAutoField"])
|
---|