Sunday, August 23, 2015

Re: DRF and self join

Thanks James. I had seen this link earlier but was not sure if I understood it right. Revisiting this link after your post made it clear.

Thanks again for the pointer.

- Shekar

On Thursday, 20 August 2015 22:26:39 UTC-7, James Schneider wrote:

Have a look at this SO post that the DRF author responded to for a similar situation.

http://stackoverflow.com/questions/13376894/django-rest-framework-nested-self-referential-objects

As far as the view, you'll need to be more specific about what you want the view to do. The serializer is probably the hard part though.

-James

On Aug 20, 2015 9:12 PM, "Shekar Tippur" <cti...@gmail.com> wrote:
Hello,

I am looking for a model/serializer/view for a self join. I can have nested paernt child relationship.

The one I am trying:

model:

class ParentChild(models.Model):
     parent=models.CharField(max_length=100blank=Falsedefault=''unique=True)
     child=models.ForeignKey('self'blank=Truenull=True )

Serializer

class ParentChileSerializer(serializers.ModelSerializer):
class Meta:
model = ParentChild
fields = ('id', 'parent','child_id')

View

??

Not sure how to proceed. Appreciate any help.

- Shekar

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b4bd6e40-b9ac-4b55-8631-f06417634b3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/17cc7ee1-205d-45f1-be61-0026b8ce4540%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment