def __init__(self, *args, **kwargs):
        super(StyledLinkForm, self).__init__(*args, **kwargs)

        #
        # Combine object_type and object_id into a single 'int_destination'
        # field Get all the objects that we want the user to be able to choose
        # from.
        #
        # For the objects, if its not convenient to sort in the queryset, (I'm
        # looking at you django-cms), then just set 'sorted=False' and we'll
        # do it below, based on the sort values.
        #
        available_objects = []

        for item in STYLEDLINK_MODELS:
            if 'type' in item:
                model = item['type']
            else:
                model = item['_cls_name']

            parts = item['class_path'].rsplit('.', 1)
            cls = getattr(import_module(parts[0]), parts[1])
            queryset = cls.objects

            if 'manager_method' in item:
                queryset = getattr(queryset, item['manager_method'])()

            if 'filter' in item:
                for (k, v) in item['filter'].items():
                    try:
                        # Attempt to execute any callables in the filter dict.
                        item['filter'][k] = v()
                    except __HOLE__:
                        # OK, it wasn't a callable, so, leave it be
                        pass
                queryset = queryset.filter(**item['filter'])
            else:
                if not 'manager_method' in item:
                    queryset = queryset.all()

            if 'order_by' in item:
                queryset = queryset.order_by(item['order_by'])

            available_objects.append({
                'model': model,
                'objects': list(queryset),
            })

        # Now create our list of choices for the <select> field
        object_choices = []
        object_choices.append(("", "--", ))

        for group in sorted(available_objects):

            obj_list = []
            for obj in group['objects']:

                type_class = ContentType.objects.get_for_model(obj.__class__)
                type_id = type_class.id
                obj_id = obj.id
                form_value = "type:%s-id:%s" % (type_id, obj_id)
                display_text = str(obj)

                obj_list.append((form_value, display_text))

            object_choices.append(( group['model'], obj_list, ))

        self.fields['int_destination'].choices = object_choices

        # If there is an existing value, pre-select it
        if self.instance.int_destination:
            type_class = ContentType.objects.get_for_model(self.instance.int_destination.__class__)
            type_id = type_class.id
            obj_id = self.instance.int_destination.id
            current_value = "type:%s-id:%s" % (type_id, obj_id)
            self.fields['int_destination'].initial = current_value
dataset/ETHPy150Open mkoistinen/djangocms-styledlink/djangocms_styledlink/forms.py/StyledLinkForm.__init__