can't adapt type error with models
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Sometimes with Django you want to perform operations which need to pickle model objects, you end up with a can't adapt type error. This is often true when one uses celery, for example.
I have a simple way to resolve this issue for model classes, but I wonder if it's relevant to add this code to Django itself.
This would be a new function in the django.db.models.base.Model class
def __reduce__(instance): names = [f.name for f in instance._meta.fields] attributes = dict([(name, getattr(instance, name)) for name in names]) return (instance.__class__, (), attributes)
Worth adding or not ?