Permalink
Browse files

Merge pull request #1 from atkinson/api-tidy

Api tidy : Prevent regular Django inlines from overwriting those declared in _EventAdmin
  • Loading branch information...
2 parents 74a463f + 94cf81e commit 806c24ceb038c5472363a710260f3b986e36c3e1 @cogat cogat committed Apr 11, 2012
Showing with 23 additions and 7 deletions.
  1. +23 −7 eventtools/admin.py
View
@@ -237,14 +237,30 @@ class _EventAdmin(SuperModel):
change_form_template = 'admin/eventtools/event.html'
save_on_top = True
prepopulated_fields = {'slug': ('title', )}
- inlines = [
- OccurrenceInline(EventModel.OccurrenceModel()),
- GeneratorInline(EventModel.GeneratorModel()),
- ]
- if show_exclusions:
- inlines += [
- ExclusionInline(EventModel.ExclusionModel()),
+
+ def append_eventtools_inlines(self, inline_instances):
+ eventtools_inlines = [
+ OccurrenceInline(EventModel.OccurrenceModel()),
+ GeneratorInline(EventModel.GeneratorModel()),
]
+ if show_exclusions:
+ eventtools_inlines.append(ExclusionInline(EventModel.ExclusionModel()))
+
+ for inline_class in eventtools_inlines:
+ inline_instance = inline_class(self.model, self.admin_site)
+ inline_instances.append( inline_instance )
+
+
+ def get_inline_instances(self, request):
+ """
+ This overrides the regular ModelAdmin.get_inline_instances(self, request)
+ """
+ # Get any regular Django inlines the user may have defined.
+ inline_instances = super(_EventAdmin, self).get_inline_instances(request)
+ # Append our eventtools inlines
+ self.append_eventtools_inlines(inline_instances)
+ return inline_instances
+
def __init__(self, *args, **kwargs):
super(_EventAdmin, self).__init__(*args, **kwargs)

0 comments on commit 806c24c

Please sign in to comment.