Quantcast
Viewing all articles
Browse latest Browse all 37

Django rest framework displaying specific field of a model

In my model:

from django.contrib.auth.models import Userclass Restaurant(models.Model):    manager = models.ForeignKey(User, on_delete=models.PROTECT,                                  null=True, blank=False, related_name="manager")

in my serializers.py

class RestaurantSerializer(CoreHyperlinkedModelSerializer):    class Meta:        model = Restaurant

in my views.py

class RestaurantViewSet(viewsets.ModelViewSet):    queryset = Restaurant.objects.order_by('id').all()    serializer_class = RestaurantSerializer

on my list:

the manager is displaying as <rest_framework.relations.PKOnlyObject object at 0x9f7040xbc208>

How can I display it as normal data like its username?


Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>