Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #822 from akatsoulas/add-event-metrics-admin
Browse files Browse the repository at this point in the history
Add metrics in the event resource.
  • Loading branch information
akatsoulas committed Sep 24, 2014
2 parents 041d7c9 + 3a3feae commit 19998f5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion remo/events/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class EventGoalAdmin(ExportMixin, admin.ModelAdmin):
class EventResource(resources.ModelResource):
event_goals = fields.Field()
event_categories = fields.Field()
event_metrics = fields.Field()

class Meta:
model = Event
exclude = ('id', 'categories', 'goals',)
exclude = ('id', 'categories', 'goals', 'metrics',)

def dehydrate_event_goals(self, event):
if event.goals.all().exists():
Expand All @@ -36,6 +37,19 @@ def dehydrate_event_categories(self, event):
return categories
return ''

def dehydrate_event_metrics(self, event):
event_metrics = event.metrics.all()
if event_metrics.exists():
event_outcome = EventMetricOutcome.objects.filter(event=event)
if event_outcome.exists():
outcome = [(x.metric.name, x.expected_outcome, x.outcome)
for x in event_outcome]
return str(outcome).strip('[]')
else:
metrics = ', '.join(x.name for x in event_metrics)
return metrics
return ''


class EventAdmin(ExportMixin, admin.ModelAdmin):
"""Event Admin."""
Expand Down

0 comments on commit 19998f5

Please sign in to comment.