add inline html
[django-migdal.git] / migdal / fields.py
1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django.db import models
6
7 class SlugNullField(models.SlugField):
8     description = "SlugField that stores NULL instead of blank value."
9
10     def to_python(self, value, **kwargs):
11         value = super(SlugNullField, self).to_python(value, **kwargs)
12         return value if value is not None else u""
13
14     def get_prep_value(self, value, **kwargs):
15         value = super(SlugNullField, self).get_prep_value(value, **kwargs)
16         return value or None
17
18
19 try:
20     # check for south
21     from south.modelsinspector import add_introspection_rules
22 except ImportError:
23     pass
24 else:
25     add_introspection_rules([], ["^migdal\.fields\.SlugNullField"])