Skip to content

Instantly share code, notes, and snippets.

@whchi
Last active June 8, 2023 03:21
Show Gist options
  • Select an option

  • Save whchi/43ac53031827943d15cfc94d6a67d260 to your computer and use it in GitHub Desktop.

Select an option

Save whchi/43ac53031827943d15cfc94d6a67d260 to your computer and use it in GitHub Desktop.
sinple counter for data factory
class DataFactory:
counter = count(start=1)
def model(self):
return ApplicationCarousel
def definition(self):
faker = Faker()
faker.add_provider(internet)
return {
'application_uuid': self.relation.get('application_uuid'),
'media_type': MediaType.IMAGE,
'media_url': faker.image_url(),
'sort_num': next(self.counter)
}
@classmethod
def reset_counter(cls):
cls.counter = count(start=1)
from factory import DataFactory
for i in range(6):
for j in range(2):
DataFactory().make()
DataFactory.reset_counter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment