django-autofixture
django-autofixture copied to clipboard
Add support for GenericFK fields
Added generator for GenericFK relations.
Overall method: find GenericFk fields from model._meta.virtual_fields,
add them to the list of fields to be processed, and remove the
constituent content_type and object_id fields from the processing list.
Then use the GenericFK generator to either select or create an
object to assign.
Addresses #32
Needs tests. Looks like you've got a big test suite - if you point me to where the tests should fit into the test suite I will write them.
Soooo great! Thanks for this awesome pull request.
I would say the tests for GenericFKSelector
go into autofixture_tests/tests/generator.py
were as the tests for the changes on the AutoFixture
class go into autofixture_tests/tests/base.py
. But feel free to create a new file if you think this should go somewhere else.
Cheers! :)
I think theres simpler solution exists, without monkeypatching etc.
What I dont understand is the Link
class - how it works? I think it must be used for handling nested GFK relations. Greg, can you make a commit with dtailed comments for this class and its methods?
Gosh, that is code which is over 4 years old and that I wrote in the middle of the night at that time :sweat_smile:
I just made an attempt to document but changed my mind and will try to make my best to refactor this one out and replace it with something that's easier to understand... I think that's easier and more future proof.
I think that Link
must not know anything about nested relations and represent and generalize only one relation, with a parameters such as one/many, taget content-type, target object-id (i think its enough to cover all types of relations). Nested relations can be handled by some clever recursive function (beware of inifinite recursion!), which will be invoked during fixture creation process when AutoFixture
finds any relation.
Are there plans to add this feature?
In my gfk branch, I've merged the PR and resolved the conflicts and a couple of minor issues.
Here is how I'm using AutoFixture
in models with GenericForeignKey
.
Feel free to use and/or modify it.
https://gist.github.com/alb3rto269/def529c94f47272bed8d2990c93d99f2