Closed tkrajca closed 11 years ago
Pull request comming soon ...
mommy.make or mommy.prepare, off course.
I guess this is sort of an alternative to make_recipe and prepare_recipe.
Why not create the other models recipes just with the foreign_key declaration to Prescription model?
or you can create this function, for instance:
def mymake(model, **kwargs):
if not 'prescription' in kwargs:
kwargs.update({'prescription': mommy.make_recipe('myapp.prescription')})
return mommy.make(model, **kwargs)
Ok, but if I don't want to create a recipe for all my models?
We have got lots of models, the only one that we want to have a recipe for is Prescription because it does some magic in .save(). The rest of the models have a foreign key to Prescription but if we use mommy to generate the original model, it will fail because it will try to generate the Prescription without the recipe.
If we write recipes for the rest of our models, then we might as well use fixtures.
We actually ended up "overriding" the make and prepare methods (similarly to what you suggested in the previous comment) and then putting that make/prepare into MOMMY_CUSTOM_FIELDS_GEN for foreign key, one to one field and many to many fields but that seems a little bit complicated for such a simple thing, I think.
It seems a very specific case and i don't think it's worth to handle it directly on model_mommy's api, at least for now.
But thanks anyway!
In our scenario we have a model Prescription that cannot be generated by mommy (for whatever reason we just need our special Prescription). We've got a recipe to create instances of Prescription. Also, we have got lots of other models that have foreign keys to prescription, we want these models to be generated by mommy.
So, I would like to do something like:
to get mommy to do prescription_recipe.make() whenever mommy.make() is called on the prescription model (as instance, related instance, many_to_many instance, ... always).