Django

Code

Ticket #7018 (new)

Opened 3 months ago

Last modified 4 days ago

Make ModelForm multiple inheritance is possible.

Reported by: bear330 Assigned to: nobody
Milestone: post-1.0 Component: django.newforms
Version: SVN Keywords:
Cc: robillard.etienne@gmail.com Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

If I have two ModelForm?:

class AForm(ModelForm):
    class Meta:
        model = A

class BForm(ModelForm):
    class Meta:
        model = B

class CForm(AForm, BForm):
    pass

This doesn't work because of the code:

        declared_fields = get_declared_fields(bases, attrs, False)

in ModelFormMetaclass?.

I can to this to make it work:

# Because ModelFormMetaclass will call get_declared_fields method with
# with_base_fields=False, we modify it with True.
from django.newforms import models as nmodels
gdf = nmodels.get_declared_fields
nmodels.get_declared_fields = \
    lambda bases, attrs, with_base_fields: gdf(bases, attrs, True)

But it will be nice if this behavior is default behavior.

Thanks.

Attachments

Change History

04/14/08 12:19:12 changed by bear330

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

A reference about form multiple inheritance:

http://www.djangosnippets.org/snippets/703/

05/10/08 09:32:32 changed by erob

  • cc set to robillard.etienne@gmail.com.

07/02/08 07:01:44 changed by garcia_marc

  • milestone set to post-1.0.

Add/Change #7018 (Make ModelForm multiple inheritance is possible.)




Change Properties
Action