mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-11 04:07:48 +03:00
Override _after_postgeneration to force save in User factory (#4534)
* Override _after_postgeneration to force save Saving in _after_postgeneration was automatic in Factory Boy versions below 4.0, but must be done explicitly in newer versions. * Clean up formatting
This commit is contained in:
parent
2ff9a12c30
commit
13b97de9d7
|
@ -29,6 +29,13 @@ class UserFactory(DjangoModelFactory):
|
|||
)
|
||||
self.set_password(password)
|
||||
|
||||
@classmethod
|
||||
def _after_postgeneration(cls, instance, create, results=None):
|
||||
"""Save again the instance if creating and at least one hook ran."""
|
||||
if create and results and not cls._meta.skip_postgeneration_save:
|
||||
# Some post-generation hooks ran, and may have modified us.
|
||||
instance.save()
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
django_get_or_create = ["{{cookiecutter.username_type}}"]
|
||||
|
|
Loading…
Reference in New Issue
Block a user