Closed baitcode closed 10 years ago
I've got simple_booking recipe and I want to make complex_booking recipe by simple override of few fields, currently, I have to do:
simple_booking = Recipe(Booking, name = 'Ilya', price=100, ) complex_booking = Recipe(Booking, name = 'Ilya', price=100, does_complex_stuff = True )
preferred syntax would be:
simple_booking = Recipe(Booking, name = 'Ilya', price=100, ) complex_booking = simple_booking.extend( does_complex_stuff = True )
So I monkey patched mommy with:
# Monkey patch def extend(self, **attrs): attr_mapping = self.attr_mapping.copy() attr_mapping.update(attrs) return Recipe(self.model, **attr_mapping) Recipe.extend = extend
But monkey patching is inconvenient. Any chance that you'll implement something like this? Or you want to me make pull request with that code?
Indeed. I rather have an extend method in the Recipe class. If you're going to send the PR, don't forget to add tests and docs.
thanks
I've got simple_booking recipe and I want to make complex_booking recipe by simple override of few fields, currently, I have to do:
preferred syntax would be:
So I monkey patched mommy with:
But monkey patching is inconvenient. Any chance that you'll implement something like this? Or you want to me make pull request with that code?