Django admin save error: get_db_prep_value() got an unexpected keyword argument 'connection' Django admin save error: get_db_prep_value() got an unexpected keyword argument 'connection' django django

Django admin save error: get_db_prep_value() got an unexpected keyword argument 'connection'


Yes, that would be a fair assumption. As you can see from the source code, the signature of that method is def get_db_prep_value(self, value, connection, prepared=False), so any subclass needs to either expect the same arguments or take *args, **kwargs.


Daniel Roseman pretty much answered this, but I will state it in another way and use more words so that you hopefully understand. For custom fields in Django 1.4.x, your custom field's get_db_prep_value function MUST NOW ACCEPT 4 parameters. In Django 1.2, the Django developers introduced multiple database support. In Django 1.4.x, the developers REMOVED code that would've allowed your function declaration to work.

So what do you need to do? You need to redefine HibernateBooleanField.get_db_prep_value to accept the extra arguments. Change your get_db_prep_value function like I have below, and it will work :)

def get_db_prep_value(self, value, connection, prepared=False):    return 0x01 if value else 0x00

Django documentation reference: https://docs.djangoproject.com/en/1.2/howto/custom-model-fields/#django.db.models.Field.get_db_prep_value