diff --git a/dr_botzo/dispatch/models.py b/dr_botzo/dispatch/models.py index c386e81..cc26e47 100644 --- a/dr_botzo/dispatch/models.py +++ b/dr_botzo/dispatch/models.py @@ -32,7 +32,7 @@ class DispatcherAction(models.Model): (FILE_TYPE, "Write to file"), ) - dispatcher = models.ForeignKey('Dispatcher') + dispatcher = models.ForeignKey('Dispatcher', related_name='actions') type = models.CharField(max_length=16, choices=TYPE_CHOICES) destination = models.CharField(max_length=200) diff --git a/dr_botzo/dispatch/serializers.py b/dr_botzo/dispatch/serializers.py index fb92bf4..500aa9d 100644 --- a/dr_botzo/dispatch/serializers.py +++ b/dr_botzo/dispatch/serializers.py @@ -5,13 +5,6 @@ from rest_framework import serializers from dispatch.models import Dispatcher, DispatcherAction -class DispatcherSerializer(serializers.ModelSerializer): - - class Meta: - model = Dispatcher - fields = ('id', 'key') - - class DispatcherActionSerializer(serializers.ModelSerializer): class Meta: @@ -19,6 +12,15 @@ class DispatcherActionSerializer(serializers.ModelSerializer): fields = ('id', 'dispatcher', 'type', 'destination') +class DispatcherSerializer(serializers.ModelSerializer): + + actions = DispatcherActionSerializer(many=True, read_only=True) + + class Meta: + model = Dispatcher + fields = ('id', 'key', 'actions') + + class DispatchMessageSerializer(serializers.Serializer): message = serializers.CharField() diff --git a/dr_botzo/dispatch/views.py b/dr_botzo/dispatch/views.py index 9e8f17c..938e3fe 100644 --- a/dr_botzo/dispatch/views.py +++ b/dr_botzo/dispatch/views.py @@ -57,7 +57,7 @@ class DispatchMessage(generics.GenericAPIView): dispatcher = self.get_object() message = self.serializer_class(data=request.data) if message.is_valid(): - for action in dispatcher.dispatcheraction_set.all(): + for action in dispatcher.actions.all(): if action.type == DispatcherAction.PRIVMSG_TYPE: bot_url = 'http://{0:s}:{1:d}/'.format(settings.IRCBOT_XMLRPC_HOST, settings.IRCBOT_XMLRPC_PORT) bot = xmlrpclib.ServerProxy(bot_url)