Closed mrmachine closed 4 years ago
This sounds to be an interesting feature. I am out of time to implement this right now, but if you implement this with automated tests and make a pull request I will merge it.
It appears to me this can have a very isolated implementation with just a small change in the G/F functions that will read this parameters _get and _update.
I was thinking about that, I guess the simplest solution to populate a DB is using a random fixture. It could have some integrity error eventually, but it shouldn't be very critical since these data should be for testing purposes.
Another possible solution:
teach(YourModel, your_field=lambda x: YourModel.objects.last().id+1)
Then it will simulate a SequentialDataFixture for you. Maybe I will include something like this into the core.
I'd like to be able to specify some unique combination of fields to
G
(orF
) and have DDF try to get the matching object and either update or create... I imagine it working like this:I want to use DDF with a custom management function to quickly populate test data to play with interactively (not in a test case).
Using the default sequential data fixture I quickly run into integrity errors. Using the random data fixture I might avoid them briefly, but still quickly run into problems.
Adding
get_or_create
andupdate_or_create
support I could safely re-run my management command any time to create missing or update existing test data.