how to define models in DJANGO 1.9

43 Views Asked by At

I have a model for a project in which I have to use Django and DRF. So I'm making a different file which takes all the objects from my model instances and provide a serializing. But in case of django 1.9 I'm not able to use Model.serializer

 from rest_framework import serializers
 from slack.models import WebhookTransaction
 from slack.message import Message

 class WebhookTransactionSerializer(serializers.ModelSerializer)
 class Meta:
    model = WebhookTransaction
    fields = '_all_'

 class MessageSerializer(serializers.ModelSerializer)
 class Meta:
    model = Message
    fields = '_all_'

After running the server it's giving me this error

File "/Users/sid/webhook10/tutorial/slack/serializer.py", line 8
class MessageSerializer(serializers.ModelSerializer)
                                                   ^
SyntaxError: invalid syntax
1

There are 1 best solutions below

0
Ausaf On

As wmorrell mentioned in the comment,

The class definition has to end with a :, and the following definitions need to be indented.

Add semi-colon after your serializers class definations, and indent the code following it, as follows

from rest_framework import serializers
from slack.models import WebhookTransaction
from slack.message import Message

class WebhookTransactionSerializer(serializers.ModelSerializer):
    class Meta:
        model = WebhookTransaction
        fields = '_all_'

class MessageSerializer(serializers.ModelSerializer):
    class Meta:
       model = Message
       fields = '_all_'