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?
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-rest-framework/f48d0db5-2d1e-451a-a99f-549f200f2ae0%40googlegroups.com.