tags:

views:

283

answers:

1

So I have a class, specifically, this:

class ProductVariantForm_PRE(ModelForm):
    class Meta:
        model = ProductVariant
        exclude = ("productowner","status")
    def clean_meta(self):

        if len(self.cleaned_data['meta']) == 0:
            raise forms.ValidationError(_(u'You have to select at least 1 meta attribute.'))

        for m in self.cleaned_data['meta']:
            for n in self.cleaned_data['meta']:
                if m != n:
                    if m.name == n.name:
                        raise forms.ValidationError(_(u'You can only select 1 meta data of each type. IE: You cannot select 2 COLOR DATA (Red and Blue). You can however select 2 different data such as Shape and Size.'))
        return self.cleaned_data['meta']

I wish to extend this class (a ModelForm), and so I have a class B.

Class B will look like this:

class B(ProductVariantForm_PRE):

How can I access the inner class "Meta" in class B and modify the exclude field?

Thanks!

+1  A: 

Take a look at the Django documentation for model inheritance here. From that page:

When an abstract base class is created, Django makes any Meta inner class you declared in the base class available as an attribute. If a child class does not declare its own Meta class, it will inherit the parent's Meta. If the child wants to extend the parent's Meta class, it can subclass it. For example:

class CommonInfo(models.Model):
    ...
    class Meta:
        abstract = True
        ordering = ['name']

class Student(CommonInfo):
    ...
    class Meta(CommonInfo.Meta):
        db_table = 'student_info'
scompt.com
I just realized you're talking about a Django Form class. I'm not sure if my answer applies.
scompt.com
this should work. thanks!
nubela