title: Creating multiple objects with foreign key
body: <p>I need to create ten sample users (<code>User</code>) and each of them must have fifty documents (<code>Doc</code>). How to do this in tests.py using factoryboy?</p>
  
  <pre><code>#factories.py
  
  from app_name.models import *
  import factory
  from datetime import datetime, timedelta, time
  from django.contrib.auth.models import User
  
  
  class UserFactory(factory.Factory):
      FACTORY_FOR = User
  
      username = factory.Sequence(lambda n: 'User ' + n)
      email = 'demo@mail.com'
      password = '1234567'
  
  class DocFactory(factory.Factory):
      FACTORY_FOR = Doc
  
      user = factory.SubFactory(UserFactory)
      kategories = '1'
      doc_number = '12345678'
      date_join = factory.Sequence(lambda n:(datetime.now() + timedelta(days=n)).date(), int)
  </code></pre>
  
  <p>in my tests.py:</p>
  
  <pre><code>from django.test import TestCase
  from django_dynamic_fixture import G
  from factories import *
  </code></pre>