I want to create serializers for my models : 1. User Model of django.auth (for which I have successfully created); and this user model is foreign key to another model as follows:
class cb_data(models.Model):
fk = models.ForeignKey(User , null =True, on_delete=models.CASCADE)
#contacts
prefix = models.CharField(max_length = 4)
phone = models.CharField(max_length = 10)
#and many more fields...
My serializer.py for the models are as follows:
class CB_data_Serializer(serializers.ModelSerializer):
# fk = cb_user_Serializer(many = True)
class Meta:
model = cb_data
fields = ['id',
'landmark','city','state','country','pincode',
'prefix', 'phone','visual_impaired','wheelchair_user',
'hearing_impaired','speech_impaired','roomtype1','roomtype2',
'roomtype3', 'pricetype1','pricetype2','pricetype3','numOftype1',
'numOftype2','numOftype3','facilityoftype1','facilityoftype2',
'facilityoftype3'
]
class cb_user_Serializer(serializers.ModelSerializer):
data = CB_data_Serializer(many = True)
class Meta:
model = cb
fields = [
'id','username', 'first_name', 'email','data'
]
I am getting this error as stated.. Please help me with the same