django-fixture-magic
django-fixture-magic copied to clipboard
Custom dump nested deps
Currently if you have multiple levels of dependencies, custom_dump command only goes one level deep through straight foreign keys and not reverse foreign keys. It goes from the parent to get the children, but will only get grandchild if it can access it directly from the parent.
It would be nice to be able to use something like
CUSTOM_DUMPS = {
'addon': { # Initiate dump with: ./manage.py custom_dump addon id
'primary': 'addons.addon', # This is our reference model.
'dependents': [ # These are the attributes/methods of the model that we wish to dump.
'current_version',
'current_version.files.all.0',
{
'primary': 'previous_versions.all',
'dependents': ['files.all']
}
],
'order': ('app1.model1', 'app2.model2',),
'order_cond': {'app1.model1': lambda x: 1 if x.get('fields').get('parent_model1') else 0,
'app2.model2': lambda x: -1 * x.get('pk')},
}
}
@dwatkinsweb this seems interesting - looks like you are taking a stab at this, when you do submit a PR mind adding some tests for this case?
@davedash I can add some unit tests for this and hopefully have a pull request in the next couple days. I have limited time to work on it in the evening. I just hacked something quickly together that works for my specific use case but shouldn't require much more to it to be more universal and I can try to add a few unit tests to it as well.
No worries, and take your time. I understand time limits and OSS. :)