Serializing booleans correctly when doing dumpdata from a MySQL database using Django 0.96

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# In django/core/serializers/python.py add these two lines to the handle_field method:

if isinstance(field, models.BooleanField) and isinstance(self._current[field.name], int):
    self._current[field.name] = bool(self._current[field.name])

# Original method

     def handle_field(self, obj, field):
         self._current[field.name] = getattr(obj, field.name)


# Modified method

     def handle_field(self, obj, field):
         self._current[field.name] = getattr(obj, field.name)
         if isinstance(field, models.BooleanField) and isinstance(self._current[field.name], int):
             self._current[field.name] = bool(self._current[field.name])

More like this

  1. CSV serializer by stringify 3 years, 6 months ago
  2. Export Models by brunobord 5 years, 10 months ago
  3. Command to make fixtures. by buriy 5 years, 9 months ago
  4. GeoJSON Serializer for GeoDjango (gis) by danielsokolowski 2 years, 11 months ago
  5. Updated: GeoJSON Serializer for GeoDjango (gis) by danielsokolowski 2 years, 5 months ago

Comments

(Forgotten your password?)