Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone-Relational and Django-Tastypie: many-to-many fields operating example
    primarykey
    data
    text
    <p>May somebody provide an example of operating with many-to-many fields of django.db models' instances through django-tastypie and backbone-relational? That's possible now with using intermediate model.</p> <pre class="lang-python prettyprint-override"><code>from django.db import models class Author(models.Model): name = models.CharField(max_length=42) class Book(models.Model): authors = models.ManyToManyField(Author, related_name='books', through='Authorship') title = models.CharField(max_length=42) class Authorship(models.Model): author = models.ForeignKey(Author) book = models.ForeignKey(Book) </code></pre> <p>Here are possible tastypie resources' configuration:</p> <pre class="lang-python prettyprint-override"><code>from tastypie import fields, resources class AuthorResource(resources.NamespacedModelResource): books = fields.ToManyField('library.api.resources.AuthorshipResource', 'books') class Meta: resource_name = 'author' queryset = models.Author.objects.all() class BookResource(resources.NamespacedModelResource): authors = fields.ToManyField('library.api.resources.AuthorshipResource', 'authors') class Meta: resource_name = 'book' queryset = models.Book.objects.all() class AuthorshipResource(resources.NamespacedModelResource): author = fields.ToOneField('library.api.resources.AuthorResource', 'author') book = fields.ToOneField('.api.resources.BookResource', 'book') class Meta: resource_name = 'authorship' queryset = models.Authorship.objects.all() </code></pre> <p>How to save Author related with a few unsaved yet Books using one request to our server?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload