Model.py
class Server(models.Model):
label = models.TextField(max_length=200,null=True) #compare this
upload1 = models.FileField(null=True, blank=True)
Image1 = models.TextField(upload1, null=True)
class Android(models.Model):
label=models.TextField(max_length=200,null=True) #with this
imagestring=models.TextField(null=True,blank=True)
returnlabel=models.TextField(null=True,blank=True)
So in my serializer class i am comparing labels from Android model and server model in (def get_returnlabel),and i want to return this label back to my android app.Any suggestons on how to do it.On my android app I am using async http.
Serializer.py
class FoodSerializers(serializers.HyperlinkedModelSerializer):
class Meta:
model=Server
fields=('url','label','Image1','upload1')
class AndroidSerializers(serializers.ModelSerializer):
class Meta:
model = Android
fields = ('label', 'imagestring', 'returnlabel') (<--returnlabel back to android app)
#Compare label from Server and Android
def get_return_label(self, obj):
queryset = Server.objects.filter( labelServer=obj.label)
queryset_serializer = FoodSerializers( queryset, many=True, read_only=True)
return queryset_serializer.data
Views.py
class FoodViewSet(viewsets.ModelViewSet):
queryset = Server.objects.all()
serializer_class =FoodSerializers
class Androids(viewsets.ModelViewSet):
queryset =Android.objects.all()
serializer_class = AndroidSerializers
get_return_label(self, obj)where wouldobjcome from? Would this be looked up from the incoming request?get_return_label()so that your Android application can retrieve the data from it remotely?get_return_label(), what parameters will it send? Perhaps you could post that code if you have written it.