I need to write a custom dumpdata command for a certain sort of objects in the database.
I looked into the code of dumpdata command and found out that it is not possible to overwrite the get_objects method which is an iterator defined inside the Handle method of the command.
Is there any reason for this?
My python expertise does not allow me to write a suggestion but I believe it would be very handy to be able to customize just the get_object iterator.
I would think that you could create your own command using django.core.management.commands.dumpdata.Command as the parent class, and override that method.
Thanks for the answer. Here is a more detailed question:
Is there any technical reason for making the get_objects iterator of the dumpdata command, (in version 5.2 it is in line 184) a local function within the handle method, rather than a method of the command which could then be overwritten?
The only Google group thread I can see referencing this ticket is
and
(Neither of these address the particulars regarding the “why” it was done this way, and the latter thread is the only conversation I can find even referencing this ticket.)
If it’s really important to you, you could always try refactoring the code and then running the applicable tests to ensure that the performance and resource envelopes aren’t changed. It’s certainly possible that improvements in Python make it possible to change this without adverse effects.
Thank you for your answer. I did try to refactor the code to make the iterator a method. But it turns out that the handle method prepares all the standard arguments for the dumpdata command. Therefore it does not make very much sense to intend to overwirte just the get-objects iterator withou overwriting the handle method. So I am going to go for a specific custom command and copy part of the code of dumpdata command. I thought ther was a smarter way but I guess this is not the case. Thanks for helping me to decide!…