Relation does not exist in Nested Serialization

24 views
Skip to first unread message

Yery cs

unread,
Dec 9, 2019, 10:10:56 PM12/9/19
to Django REST framework
Hello.
I am using Django Rest Framework and PostgreSQL Multi schemas.

from accounts.models import User
from myData.models import Private_ID_Info

class PrivateIDInfoSerializer(serializers.ModelSerializer):
class Meta:
model = Private_ID_Info
fields = ('first_name', 'last_name', )

class UserInfoSerializer(serializers.ModelSerializer):
privateIdInfo = PrivateIDInfoSerializer(many=True, read_only=True, source='private_id_info_set')

class Meta:
model = User
fields = ('id', 'username', 'email', 'role', 'privateIdInfo', )

Above code, you can notice, there are two relation tables, one user table and the other one is private_id_info table.
These two tables are in different schemas. The problem is DRF cannot find relation between two models.
If two tables are in same schema, the relation between two tables is recoginzed and runs well.

I am using multi schemas in PostgreSQL and in setting.py, following code is placed about multi schemas settings.

'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'OPTIONS': {
'options': '-c search_path=django,public'
},
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD': config('DB_PASSWORD'),
'HOST': config('DB_HOST'), # Or an IP Address that your DB is hosted on
},
'myData': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'OPTIONS': {
'options': '-c search_path=myData,public'
},
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD': config('DB_PASSWORD'),
'HOST': config('DB_HOST'), # Or an IP Address that your DB is hosted on
}


How can DRF recognize relation between two models in different schemas?







































Reply all
Reply to author
Forward
0 new messages