0

I am using dynamic-rest. According to the documentation, I have this model with a dynamically generated foreign key:

class PscSerializer(DynamicModelSerializer):

    class Meta:
        model = PSC
        name = 'psc'
        fields = ('id', 'description', 'created', 'modified', 'pscno', 'productno', 'serviceno', 'luns')

    luns = DynamicRelationField('LunSerializer', many=True)

Which produces:

Exception Type: AttributeError at /api/v1/pscs/
Exception Value: luns is not a valid field for <class 'pscs.models.PSC'>

Sure, luns is not a field in the PSC model, but a dynamic field. What is going on? What am I doing wrong here?

blueFast
  • 41,341
  • 63
  • 198
  • 344
  • I've never used DREST before, but in the example you point to, both the dynamic relation fields are already defined as relationships on the model. – RishiG Jun 07 '18 at 15:00
  • @RishiG thanks. That is not the model, but the serializer. I have not shown the model, since it suffices to know that `luns` is not a field, as explained. – blueFast Jun 07 '18 at 15:08
  • In the example you refer to in the documentation, the `User` model has `location` and `groups` fields, which are the dynamic relation fields in the serializer. I think it's designed to add functionality to the serializer for fields that already exist on the model. – RishiG Jun 07 '18 at 15:11

0 Answers0