1👍
✅
The problem was that CourseFactory()
already creates a CourseInfo object. I’ve resolved this by just removing the info = factory.RelatedFactory(CourseInfoFactory, 'course')
line, and now the CourseInfoFactory is unnecessary – I can test CourseInfo by getting the created object at course.info
.
14👍
Just add the django_get_or_create in the Meta class of your CourseInfoFactory:
class Meta:
django_get_or_create = ('group',)
This solution avoids the problem of a unique constraint in your field, and creates it if exists.
You could check here: https://github.com/FactoryBoy/factory_boy/blob/v2.5.2/factory/django.py#L133-L139
- Removing a fields from a dynamic ModelForm
- How does commit_on_success handle being nested?
- Creating a list on the fly in a Django template
- Debugging slow Django Admin views
- Django : HTML form action directing to view (or url?) with 2 arguments
Source:stackexchange.com