Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Change inherited form meta class

I want to edit the Meta Class of a form that inherits its data from a ModelForm. All I want is to add one field, I don't want to repeat all the form.

# NuevaBibliotecaCompartida is a ModelForm

class EditarBibliotecaCompartida(NuevaBibliotecaCompartida):

    class Meta:
        fields = ('nombre', 'direccion', 'imagen', 'punto_google_maps')

I get the error ModelForm has no model class specified, of course, because I am overriding the Meta class when I add a field. How can I solve this?

like image 447
Alejandro Veintimilla Avatar asked Nov 05 '15 01:11

Alejandro Veintimilla


1 Answers

You need to explicitly subclass the parent's Meta class:

class Meta(NuevaBibliotecaCompartida.Meta):
    # `model` will now be inherited
    fields = ('nombre', 'direccion', 'imagen', 'punto_google_maps')
like image 147
solarissmoke Avatar answered Oct 13 '22 10:10

solarissmoke