Ticket #18201: custommodels.py

File custommodels.py, 1.9 KB (added by michael.frere@…, 13 years ago)

custom model fields tryout

Line 
1#!/usr/bin/env python
2
3from django.db.models.fields import (SmallIntegerField,
4 PositiveSmallIntegerField,
5 AutoField)
6
7from django.conf import settings
8
9class 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
17class 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
25class 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
35class 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
45from south.modelsinspector import add_introspection_rules
46add_introspection_rules([], ["^liveview\.livedata\.custommodels\.PositiveTinyIntegerField"])
47add_introspection_rules([], ["^liveview\.livedata\.custommodels\.TinyIntegerField"])
48add_introspection_rules([], ["^liveview\.livedata\.custommodels\.PositiveSmallAutoField"])
49add_introspection_rules([], ["^liveview\.livedata\.custommodels\.PositiveTinyAutoField"])
Back to Top