Hi
I'm trying to change the extra value based on a related object's
attribute.
The relevant bit of code starts with: ## begin alterations
This way of doing it works, but should I be calling super() at the
end? if so, why?
I've been reading up on super a lot.
--------------------------------------------------------
from admin.py
--------------------------------------------------------
class HDChannelInline(admin.TabularInline):
model = HDChannel
extra = 0
template = 'admin/edit_inline/tabular.html'
def get_formset(self, request, obj=None, **kwargs):
"""Returns a BaseInlineFormSet class for use in admin add/
change views."""
if self.declared_fieldsets:
fields = flatten_fieldsets(self.declared_fieldsets)
else:
fields = None
if self.exclude is None:
exclude = []
else:
exclude = list(self.exclude)
defaults = {
"form": self.form,
"formset": self.formset,
"fk_name": self.fk_name,
"fields": fields,
"exclude": exclude + kwargs.get("exclude", []),
"formfield_callback": self.formfield_for_dbfield,
"extra": self.extra,
"max_num": self.max_num,
}
## begin alterations
if obj is not None:
if obj.asset_type == 'broadcast_radio':
defaults['extra'] = 2
## end alterations
defaults.update(kwargs)
return inlineformset_factory(self.parent_model, self.model,
**defaults)
--
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.