Example #1
0
class RoleForm(forms.ModelForm):
    units = forms.MultipleModelChoiceField(Unit.objects.all(), label=u'Unidades', required=False)

    class Meta():
        model = Role
        fields = ('id',)

    def __init__(self, *args, **kwargs):
        super(RoleForm, self).__init__(*args, **kwargs)
        self.fields['units'].initial = self.instance.units.values_list('id', flat=True)
Example #2
0
    class Form(forms.ModelForm):
        related_objects = forms.MultipleModelChoiceField(
            related_field_model.objects.all(),
            label=get_metadata(related_field_model, 'verbose_name'))

        class Meta:
            model = _model
            fields = ()
            title = u'Adicionar %s' % get_metadata(related_field_model,
                                                   'verbose_name')
            icon = get_metadata(related_field_model, 'icon', None)

        def save(self, *args, **kwargs):
            for related_object in self.cleaned_data['related_objects']:
                getattr(self.instance, related_field_name).add(related_object)
Example #3
0
    class Form(forms.ModelForm):
        related_objects = forms.MultipleModelChoiceField(
            related_field_model.objects.all(),
            label=get_metadata(related_field_model, 'verbose_name'))

        class Meta:
            model = _model
            fields = ()
            title = 'Adicionar {}'.format(
                get_metadata(related_field_model, 'verbose_name'))
            icon = get_metadata(related_field_model, 'icon', None)
            # is_inner = True

        def save(self, *args, **kwargs):
            for related_object in self.cleaned_data['related_objects']:
                getattr(related_object,
                        field.rel.remote_field.name).add(self.instance)
            self.instance._check_role()