def handle_fk_field(self, obj, field):
        related = getattr(obj, field.name)

        if related is not None:
            related = utils.lookup_pattern_from_instance(related)
            #if field.rel.field_name == related._meta.pk.name:
            #    # Related to remote object via primary key
            #    related = related._get_pk_val()
            #@todo consider this case:
            #else:
            #    # Related to remote object via other field
            #    related = getattr(related, field.rel.field_name)
        #self._current[field.name] = smart_unicode(related, strings_only=True)
        self._current[field.name] = related
 def test_lookup_pattern_generation(self):
     self.assertEqual(lookup_pattern_from_instance(OnlyPkModel.objects.get(pk=1)), 1)
     self.assertEqual(lookup_pattern_from_instance(SlugModel.objects.get(pk=1)), 1)
     self.assertEqual(lookup_pattern_from_instance(UniqueSlugModel.objects.get(pk=1)),
                      {'slug': 'bar'})
     self.assertEqual(lookup_pattern_from_instance(UniqueIntModel.objects.get(pk=1)),
                      {'val': 1})
     self.assertEqual(lookup_pattern_from_instance(TwoUniqueIntsModel.objects.get(pk=1)),
                      {'val1': 1, 'val2': 2})
     self.assertEqual(lookup_pattern_from_instance(UniqueTogetherModel.objects.get(pk=1)),
                      {'val1': 1, 'val2': 2})
     self.assertEqual(lookup_pattern_from_instance(UniqueTogetherAndUniqueModel.objects.get(pk=1)),
                      {'val1': 1, 'val2': 2, 'val3': 3})
 def handle_m2m_field(self, obj, field):
     if field.creates_table:
         self._current[field.name] = [utils.lookup_pattern_from_instance(related)
                            for related in getattr(obj, field.name).iterator()]