3👍
You can use exclude, which has been added in 2.4.0
See http://factoryboy.readthedocs.org/en/latest/reference.html#factory.FactoryOptions.exclude
1👍
You can customize the _create method.
You can also disable signals if the external account is created in a signal handler.
- [Django]-PyCharm doesn't recognise my VirtualEnv installed modules
- [Django]-How to download data from azure-storage using get_blob_to_stream
- [Django]-Django FilteredSelectMultiple not rendering on page
- [Django]-Change model to inherit from abstract base class without changing DB
- [Django]-Django Application: Foreign Key pointing to an abstract class
1👍
factory_boy
‘s create()
calls your model’s MyModel.objects.create(**kwargs)
method.
When you write MyModelFactory()
, this calls:
obj = MyModel(name="name01", create_external_account=False)
obj.save()
return obj
Here, you should override your model’s __init__
method to handle your custom field:
class MyModel(django.db.models.Model):
def __init__(self, *args, **kwargs):
self.create_external_account = kwargs.pop('create_external_account', False)
return super(MyModel, self).__init__(*args, **kwargs)
- [Django]-Unicode error when saving an object in django admin
- [Django]-Django's list_details views saving queryset to memory (not updating)?
- [Django]-DRF : parameter in custom permission class with function based views
- [Django]-Django failing to cascade-delete related generic foreign key object
- [Django]-ModuleNotFoundError: No module named 'debug_toolbar' Django 3.1
Source:stackexchange.com