def test_column_choices(self):
        class OneToOneToExport(models.Model):
            """Fake model.

            Make sure that get_choices works with
            SingleRelatedObjectDescriptor, as explained in ticket #4.

            """
            name = models.CharField(max_length=50)
            o2o = models.OneToOneField(Export)

        # reload the model's relations, to have the OneToOneToExport's relation
        # taken into account
        self.empty_export._meta._fill_related_objects_cache()
        self.empty_export._meta.init_name_map()

        ColumnInlineFormSet = inlineformset_factory(Export,
                                                    Column,
                                                    form=ColumnForm,
                                                    formset=ColumnFormSet)
        formset = ColumnInlineFormSet(instance=self.empty_export)
        # the column field has choices
        form = formset.forms[0]
        self.assertTrue(hasattr(form.fields['column'], 'choices'))
        choices = form.fields['column'].choices
        # all the model items are in the column field choices
        self.assertTrue(all([(i, i) in choices for i in self.im.items]))
        # and all the related model items are in the fields choices
        # export has a FK to Format named 'export_format'
        im_format = ['export_format.%s' % i
                     for i in InspectModel(Format).items]
        self.assertTrue(all([(i, i) in choices for i in im_format]))
        # export has a FK to ContentType named 'model'
        im_ct = ['model.%s' % i for i in InspectModel(ContentType).items]
        self.assertTrue(all([(i, i) in choices for i in im_ct]))
        # OneToOneToExport has a OneToOneField to ContentType named
        # 'onetoonetoexport'
        im_o2o = ['onetoonetoexport.%s' % i
                  for i in InspectModel(OneToOneToExport).items]
        self.assertTrue(all([(i, i) in choices for i in im_o2o]))
        # revert changes to name_map:  'unload' the OneToOneToExport relation
        del self.empty_export._meta._name_map['onetoonetoexport']
Choices computed for the exported model
dataset/ETHPy150Open magopian/django-data-exports/data_exports/tests.py/ExportTest.test_column_choices