django-rest-framework-recursive view not returning ID

28 views
Skip to first unread message

Shekar Tippur

unread,
Aug 23, 2015, 1:05:19 PM8/23/15
to Django users

Hello,

I am using https://github.com/heywbj/django-rest-framework-recursive and it works great.


I seem to have a small issue with it. When I try a GET operation on it, I dont seem to get the ID in the result. I want ID to be part of the result so that I can filter further on parent_id.


Model:

class RecursiveModel(models.Model):
stage_title = models.CharField(max_length=255, unique=True)
parent = models.ForeignKey('self', null=True)
created = models.DateTimeField(auto_now_add=True)


View:
class MySerializer(serializers.ModelSerializer):
parent = RecursiveField(allow_null=True, read_only=True)
class Meta:
managed = True
model = RecursiveModel
fields = ( 'stage_title', 'parent')


Appreciate any help in this regard.

James Schneider

unread,
Aug 23, 2015, 2:22:07 PM8/23/15
to django...@googlegroups.com

Have you tried adding 'id' to the fields tuple?

-James

Shekar Tippur

unread,
Aug 23, 2015, 9:26:18 PM8/23/15
to Django users
James,

My bad. Sorry an obvious mistake from my side. Yes, I had forgotten ID in the serializer field.

- Shekar


Reply all
Reply to author
Forward
0 new messages