Hello @mahesh,
First you have to fetch user details. I have created Models UserProfile, serilzers and ModelViewSet like below. From below models I fetch loged in User profile details like state, city and adress etc.
class UserProfile(models.Model):
user= models.OneToOneField(User,on_delete=models.CASCADE,related_name='userprofile');
state= models.CharField(max_length=200)
city= models.CharField(max_length=200)
add1= models.CharField(max_length=200)
add2= models.CharField(max_length=200)
postalcode= models.IntegerField()
country= models.CharField(max_length=200)
class UserProfileSerializer(serializers.ModelSerializer):
class Meta:
model = UserProfile
fields = ('state','city','country')
class UserProfileViewSet(viewsets.ModelViewSet):
queryset=UserProfile.objects.all()
serializer_class=UserProfileSerializer
def get(self, request):
userProfileObj = queryset.objects.filter(user_id=request.user.id)
serializer = self.get_serializer(userProfileObj)
return Response(serializer.data)
After this you can send email to users . To know how to send mail you can refer this:https://docs.djangoproject.com/en/3.1/topics/email/
Hope it helps!!
Thank You!!