Exemple #1
0
def generate_projects():
    organisations = [org for org in Organisation.query('ORG', limit=4)]
    project_types = ['freelance', 'contract', 'full_time']
    project_status = ['pending', 'in_progress', 'on_hold', 'complete']
    for _ in range(40):
        print("Generating a project")
        organisation = random.choice(organisations)
        serializer = ProjectSerializer(
            data=dict(organisation_id=organisation.model_id,
                      name=fake.word(),
                      project_type=random.choice(project_types),
                      status=random.choice(project_status)))

        if serializer.is_valid():
            serializer.save()
Exemple #2
0
def generate_employees():
    organisations = [org for org in Organisation.query('ORG', limit=4)]

    for _ in range(20):
        print("Generating Employee")
        organisation = random.choice(organisations)

        days = [_ for _ in range(1, 29)]
        months = [_ for _ in range(1, 13)]
        years = [_ for _ in range(1993, 2001)]
        serializer = EmployeeSerializer(
            data=dict(organisation_id=organisation.model_id,
                      name=f"{fake.first_name()} {fake.last_name()}",
                      email=fake.email(),
                      date_of_birth=timezone.datetime(
                          year=random.choice(years),
                          month=random.choice(months),
                          day=random.choice(days)).strftime('%Y-%m-%d')))

        if serializer.is_valid():
            serializer.save()

        else:
            print(serializer.errors)