In a ModelForm I can write a clean_<field_name>
member function to automatically validate and clean up data entered by a user, but what can I do about dirty json or csv files (fixtures) during a manage.py loaddata
?
Fixtures loaded with loaddata
are assumed to contain clean data that doen't need validation (usually as an inverse operation to a prior dumpdata
), so the short answer is that loaddata isn't the approach you want if you need to clean your inputs.
However, you probably can use some of the underpinnings of loaddata while implementing your custom data cleaning code--I'm sure you can easily script something using the Django serialization libs to read your existing data files them in and the save the resulting objects normally after the data has been cleaned up.