Esempio n. 1
0
class CategoriaForm(ModelForm):
    def __init__(self, *args, **kwargs):
        self.edit = kwargs.pop('edit', None)
        super(CategoriaForm, self).__init__(*args, **kwargs)

        self.categoriaServicios = CategoriaServicios()

    class Meta:
        model = Categoria
        exclude = [""]
        select = {'data-placeholder': "Seleccionar", 'class': "chzn-select", 'tabindex': "2"}
        selectMultiple = {'class': 'chzn-select', 'multiple': '', 'tabindex': '15', 'style': 'width:300px'}

        widgets = {
            'responsable': forms.Select(attrs=select),
            'dependencias': forms.SelectMultiple(attrs=selectMultiple),
        }

    def save(self, commit=True):
        if not self.edit:
            categoria = super(CategoriaForm, self).save(commit=False)
            self.categoriaServicios.insert(categoria)
            self.save_m2m()
        else:
            categoria = super(CategoriaForm, self).save(commit=False)
            self.categoriaServicios.update(categoria)
            self.save_m2m()
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        self.edit = kwargs.pop('edit', None)
        super(CategoriaForm, self).__init__(*args, **kwargs)

        self.categoriaServicios = CategoriaServicios()