hagsteel / swampdragon-py-client

A python client for swamp dragon
7 stars 1 forks source link

Send data to SelfPublishModel with FK #4

Open lorddaren opened 9 years ago

lorddaren commented 9 years ago

I have been having some trouble figuring out how to post data to a table that includes a FK.

Here is what I have

# Models
class Job(SelfPublishModel, models.Model):
    serializer_class = JobSerializer
    host = models.CharField()
    status = models.CharField()

class JobOutput(SelfPublishModel, models.Model):
    serializer_class = JobOutputSerializer
    job = models.ForeignKey(Job)
    output = models.CharField()

# Serializer
class JobSerializer(ModelSerializer):
    class Meta:
        model = "app.Job"
        publish_fields = ('host', 'id', 'status)
        update_fields = ('host', 'status')

class SQLPlusJobDetailSerializer(ModelSerializer):
    job = JobSerializer
    class Meta:
        model = "deployinator.SQLPlusJobOutput"
        publish_fields = ('output', 'job')
        update_fields = ('output', 'job')

# Dragon client call.
# I have already created the ID and have the Job ID
d = DragonClient('ws://localhost:9999/data')
d.call_router('create', 'job', callback=on_create, output='Testing', job='4')

Traceback from server.py:

Traceback (most recent call last):
  File "/Users/dlord/.virtualenvs/deployinator/lib/python2.7/site-packages/sockjs/tornado/transports/websocket.py", line 62, in on_message
    self.session.on_messages((msg,))
  File "/Users/dlord/.virtualenvs/deployinator/lib/python2.7/site-packages/sockjs/tornado/session.py", line 423, in on_messages
    self.conn.on_message(msg)
  File "/Users/dlord/.virtualenvs/deployinator/lib/python2.7/site-packages/swampdragon/connections/sockjs_connection.py", line 90, in on_message
    raise e
Exception: data needs to be a dictionary
ERROR:tornado.application:Uncaught exception in /data/215/texwdnertb/websocket
Traceback (most recent call last):
  File "/Users/dlord/.virtualenvs/deployinator/lib/python2.7/site-packages/tornado/websocket.py", line 415, in _run_callback
    callback(*args, **kwargs)
  File "/Users/dlord/.virtualenvs/deployinator/lib/python2.7/site-packages/sockjs/tornado/transports/websocket.py", line 70, in on_message
    self.abort_connection()
  File "/Users/dlord/.virtualenvs/deployinator/lib/python2.7/site-packages/sockjs/tornado/websocket.py", line 28, in abort_connection
    self.ws_connection._abort()
AttributeError: 'NoneType' object has no attribute '_abort'

What am I doing wrong and how can I create a new record based on the job id?