Hi all,
I want to use a inlineformset with a highly customized form (it is
based on a specific metaclass and has a customized __init__ function).
Due to the way the inlineformset_factory function works, if I specify
my form in the form argument, the specific form instantiation does not
seem to work (because a new form class is created based on my form). I
acknowledge that this may be because my metaclass may be lacking and
therefore does not allow subclassing correctly.
In case you are wondering: this is entirely outside of the admin.
I found a way around this in creating my inlineformset as a class
directly off of BaseInlineFormSet like this:
class ReportDaysFormset(BaseInlineFormSet):
form = InlineReportDayForm
model = ReportDay
fk = (i for i in model._meta.fields if i.name == 'report').next()
can_order = False
can_delete = True
max_num = 0
extra = 3
This works well, and looks nice (I don't much like factory functions
BTW) but I wonder if this could be done easier:
1. I have to specify can_order, can_delete etc. that is there are no
default values for these
2. setting the fk attribute this way seems hackish
I think it would be nice to have a 'InlineFormSet' based on
BaseInlineFormSet that would allow to use a declarative syntax to
specify formsets and that
a. specifies defaults for can_order etc
b. allows setting the fk using a string that specifies the fieldname
of the foreign key to the parent
Am I missing the point here completely ?
Does anybody have similar experiences ?
Koen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---