Django REST Framework with ForeignKey Example

  • Posted on: 10 September 2015
  • By: oon

If you are a noob in Django or Django REST Framework (DRF),
it's pretty hard to find (complete) example about providing REST API for system with (sql relationship) foreign key on its database.

this example on SO is quite straigth forward and complete, about DRF with foreignkey.

http://stackoverflow.com/a/19414405/3991504

ya, you also get django.test.Client information as a bonus. nice!

mostly my problem is about reverse relationship [1][2][3].

[1]http://www.django-rest-framework.org/api-guide/relations/#reverse-relations
[2]http://www.django-rest-framework.org/tutorial/4-authentication-and-permi...
[3]https://docs.djangoproject.com/en/dev/topics/db/queries/#following-relat...

 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.