title: How can I set User Groups using factory_boy
body: <p>I am fairly new to Django. I am trying to set the <code>groups</code> field for <code>User</code> using <code>factory_boy</code>. The default <code>User</code> class has a field <code>_groups</code>. I tried setting that, but that is not helping.</p>
  
  <pre><code>class GroupFactory(factory.django.DjangoModelFactory):
      class Meta:
          model = Group
  
      name = Sequence(lambda n: "group_{0}".format(n))
  
  
  class UserFactory(factory.django.DjangoModelFactory):
      class Meta:
          model = User
  
      username = factory.Sequence(lambda n: "user_{0}".format(n))
      password = "test"
      first_name = u'ßhamra'
      last_name = u'ßhamra'
      _groups = factory.SubFactory(GroupFactory)
  
  
      @classmethod
      def _create(cls, model_class, *args, **kwargs):
          """
          Override the default ``_create`` with our custom call.
          Due to internal behavior or create user create method that                forces is_staff kwarg
  
  
      """
      g = GroupFactory("abc")
      manager = cls._get_manager(model_class)
      is_staff = kwargs.pop('is_staff', None)
      user = manager.create_user(*args, **kwargs)
  
  
      if is_staff:
          user.is_staff = is_staff
          user.save()
      return user
  </code></pre>