Hello All,
DRF failing to pull the data from User model
I have two Serializers for Two models(User model and UserProfile).
models.py
----------
class UserProfile(models.Model):
Photo = models.FileField(upload_to='documents/%Y/%m/%d/', null=True)
uploaded_at = models.DateTimeField(auto_now_add=True, null=True)
dob = models.DateField(max_length=20, null=True)
country = models.CharField(max_length=100, null=True)
State = models.CharField(max_length=100, null=True)
District = models.CharField(max_length=100, null=True)
phone = models.CharField(max_length=10, null=True)
def __str__(self):
return self.phone
serializers.py
-----------------
from rest_framework import serializers
from django.contrib.auth.models import User
from .models import UserProfile
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('first_name', 'last_name', 'email')
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = UserProfile
fields = ('Photo', 'dob', 'country', 'State', 'District', 'phone')
views.py
------------
class getUserProfile(generics.ListAPIView):
lookup_field = []
def get(self, *args, **kwargs):
qs = User.objects.all()
qs1 = UserProfile.objects.all()
UserData = UserSerializer(qs).data
ProfileData = ProfileSerializer(qs1).data
return Response({'UserData': UserData, 'ProfileData': ProfileData})
If you one see the above screenshot, it clearly says that "UserData" serializer doesn't getting any data, as well as the ProfileData is successfully pulling the column names, however, the values are NULL. Below screenshot show that there are data in the table
UserData
ProfileData
Please suggest.
Regards,
Amitesh
No comments:
Post a Comment