thisLabel = ClassificationLabel.objects.get(identifier=label.identifier)
AttributeError at /api/v1/policies/ 'collections.OrderedDict' object has no attribute 'identifier
class ClassificationLabelDetailSerializer(serializers.ModelSerializer):
class Meta:
model = ClassificationLabel
fields = ('displayName', 'helpText', 'identifier', 'backgroundColour', 'foregroundColour', 'comment', 'description', 'lastChanged', 'revision')
read_only_fields = ('identifier', 'lastChanged', 'revision',)
class PolicySerializer(serializers.ModelSerializer):
labels = ClassificationLabelDetailSerializer(many=True)
class Meta:
model = Policy
fields = ('displayName', 'identifier', 'labels', 'lastChanged', 'description', 'comment')
read_only_fields = ('identifier', 'lastChanged',)
def create(self,validated_data):
labelData = validated_data.pop('labels')
thisPolicy = Policy.objects.create(**validated_data)
for label in labelData:
for k, v in label.items():
print(k, v) #<=this is what I'm using to see what object attributes are available
thisLabel = ClassificationLabel.objects.get(identifier=label.identifier)#insert organisational filter here
PolicyMemberClassificationLabel.objects.create(policy=thisPolicy, label=thisLabel, order=index)
return thisPolicy
{
"labels": [
{
"displayName": "Test name",
"helpText": "Wayfarers sartorial authentic, small batch readymade disrupt coloring book. Wayfarers sartorial authentic, small batch readymade disrupt col",
"identifier": "fa27e9bd-5007-4874-b10c-46b63c7c8a86",
"backgroundColour": "#808900",
"foregroundColour": "#000000",
"comment": "Wayfarers sartorial authentic, small batch readymade disrupt coloring book.",
"description": "Wayfarers sartorial authentic, small batch readymade disrupt coloring book.",
"lastChanged": "2017-07-03T09:26:20.450681Z",
"revision": 2
},
{
"displayName": "Test name 1",
"helpText": "Wayfarers sartorial authentic, small batch readymade disrupt coloring book.",
"identifier": "29c968dd-8b83-4374-962d-32b9ef527e1b",
"backgroundColour": "#9f0500",
"foregroundColour": "#FFFFFF",
"comment": "Wayfarers sartorial authentic, small batch readymade disrupt coloring book.",
"description": "Wayfarers sartorial authentic, small batch readymade disrupt coloring book.",
"lastChanged": "2017-07-03T09:25:52.955293Z",
"revision": 2
}
]
}
read_only_fields
and that doesn't seem to make any difference