On 3 mrt, 14:09, Alex Gaynor <alex.gay...@gmail.com> wrote: > > AFAIK the intention was always to eventually have a metaclass so it looked > more like model forms, but the usecase wasn't as strong, and no one who > wanted it ever wrote any code AFAIK > > Alex
Thank you Alex, something like this seems to work: class InlineFormSetMetaclass(type): def __new__(cls, name, bases, attrs): # TODO: add some checking try: parents = [b for b in bases if issubclass(b, InlineFormSet)] except NameError: # We are defining InlineFormSet itself. parents = None new_class = super(InlineFormSetMetaclass, cls).__new__(cls, name, bases, attrs) if not parents: return new_class if 'can_order' not in attrs: new_class.can_order = False if 'can_delete' not in attrs: new_class.can_delete = False if 'max_num' not in attrs: new_class.max_num = 0 if 'extra' not in attrs: new_class.extra = 3 parent = attrs.pop('parent') model = attrs.get('model') new_class.fk = (i for i in model._meta.fields if i.name == parent).next() return new_class class InlineFormSet(forms.models.BaseInlineFormSet): __metaclass__ = InlineFormSetMetaclass Do you think this is worth a ticket ? I guess modelformset needs the same kind of love ? Koen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---