- Notifications
You must be signed in to change notification settings - Fork302
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I have the following serializers: # Module 1fromartist.serializersimportArtistSerializerclassImageSerializer(serializers.ModelSerializer):included_serializers= {"artist":ArtistSerializer }classMeta:model=Imagefields= ["artist"]# Module 2fromimage.serializersimportImageSerializerclassArtistSerializer(serializers.ModelSerializer):included_serializers= {"images":ImageSerializer }classMeta:model=Artistfields= ["images"] The images field is a reverse relationship. This raises a circular dependendy error. I have already tried importing the serializers from inside of the class, but this does not work because when one class is imported, the circular dependency problem starts again. Is there any way that this can be done without importing the serializers to each module? I cannot move the 2 serializers to the same module to fix the error since they need to be in their own apps. Is this impossible? |
BetaWas this translation helpful?Give feedback.
All reactions
Hi@Nekidev. This is a good question. Django REST framework JSON:API supports dotted import string to define included serializers.
This could look something likes this:
classImageSerializer(serializers.ModelSerializer):included_serializers= {"artist":"artist.serializers.ArtistSerializer" }classMeta:model=Imagefields= ["artist"]
Defining the serializers as dotted import string should resolve your circular import problem.
Replies: 1 comment 1 reply
-
Hi@Nekidev. This is a good question. Django REST framework JSON:API supports dotted import string to define included serializers. This could look something likes this: classImageSerializer(serializers.ModelSerializer):included_serializers= {"artist":"artist.serializers.ArtistSerializer" }classMeta:model=Imagefields= ["artist"] Defining the serializers as dotted import string should resolve your circular import problem. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Thanks, I had tried using a string but without the |
BetaWas this translation helpful?Give feedback.