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. Export Models by brunobord 3 years, 7 months ago
  2. dumpdata/loaddata with MySQL and ForeignKeys, as django command by brondsem 2 years, 9 months ago
  3. Drop all tables in MySQL database by mpasternacki 2 years ago
  4. CSV serializer by stringify 1 year, 3 months ago
  5. MySQL "Text" Type Model Field by blackbrrr 3 years, 8 months ago

Comments

(Forgotten your password?)