Last active
May 20, 2021 10:54
-
-
Save piotrkilczuk/c870a02ef16e7579a4bcfac5545a3c0d to your computer and use it in GitHub Desktop.
factories_v4.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PlayerFactory(DjangoModelFactory): | |
# other declarations removed for brevity | |
@post_generation | |
def picture(self, create, extracted, **kwargs): | |
if extracted: | |
self.picture = extracted | |
elif kwargs: | |
assert 'filename' in kwargs, 'You need to pass in the filename' | |
location = os.path.join(settings.BASE_DIR, f'fbd/championship/fixtures/{kwargs["filename"]}') | |
assert os.path.isfile(location), f'{location} does not exist' | |
self.picture = File(open(location, 'rb')) | |
if create: | |
self.save(update_fields=['picture']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment