Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dumpdata only serializes filename #11

Open
rclmenezes opened this issue Dec 18, 2013 · 2 comments
Open

Dumpdata only serializes filename #11

rclmenezes opened this issue Dec 18, 2013 · 2 comments

Comments

@rclmenezes
Copy link
Contributor

When using Django 1.5.5, I'm running into the issue where dumpdata is only outputting the filename of the CroppableImageField, without its coord_csv.

It seems that the best way to solve this is to use value_to_string():
https://docs.djangoproject.com/en/1.6/howto/custom-model-fields/#django.db.models.Field.value_to_string

Adding this to CroppableImageField seems to work for me:

def value_to_string(self, obj):
        if obj.picture:
            value = obj.picture.filename + IMAGE_FIELD_DELIMITER + obj.picture.coords_csv
        else:
            value = ''
        return self.get_prep_value(value)

Note that this doesn't solve loaddata...

Edit:
Found a way to make loaddata work! Overload get_db_prep_save():
https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/#django.db.models.Field.get_db_prep_save

def get_db_prep_save(self, value, connection):
        return value.filename + IMAGE_FIELD_DELIMITER + value.coords_csv
@danxshap
Copy link
Owner

Great finds! Any chance you can submit a pull request?

@rclmenezes
Copy link
Contributor Author

Sure, when I'm less busy! Gimme a couple of days!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants