Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I return data from a related model in Django Tastypie?
    primarykey
    data
    text
    <p>How do I bring in the information from another model?</p> <p>I have two models <code>Article</code>, and <code>ArticleBody</code></p> <p>Article containing the main info and ArticleBody containing a loop of body and image information</p> <pre><code>class Article(models.Model): author = models.ForeignKey(User) title = models.CharField(max_length=100) excerpt = models.CharField(max_length=140, null=True, blank=True, help_text='A description no longer than 140 characters that explains what the article is about, important for SEO') category = models.ManyToManyField(Category) date_published = models.DateTimeField() slug = models.SlugField(null=True) status = models.CharField(choices=STATUS, max_length=2, default='DR') tags = TagField(default='', null=True, blank=True, help_text='Just add a comma between the tags i.e. "My very important name, Hunting, Scope, Rifle"') source_name = models.CharField(default='', blank=True, null=True, help_text='Outdoor Magazine', max_length=100) source_url = models.URLField(verify_exists=False, max_length=200, null=True, blank=True, help_text='http://www.source.com/2011/01/long-name/') class ArticleBody(ImageModel): article = models.ForeignKey(Article) body = models.TextField(verbose_name='', blank=True, null=True) image = models.ImageField(storage=cloudfiles_storage, upload_to='articles', default='avatar-blank.jpg', verbose_name='', blank=True, null=True) caption = models.CharField(max_length=80, null=True, blank=True) </code></pre> <p>In my api resources.py file I am trying to get the ArticleBody information into my NewsResource...</p> <p>This is what I have so far.</p> <pre><code>class NewsBodyResource(ModelResource): class Meta: queryset = ArticleBody.objects.all() resource_name = 'article_body' class NewsResource(ModelResource): class Meta: queryset = Article.objects.filter(status='PU', date_published__lt=datetime.datetime.now).order_by('-date_published') resource_name = 'news' </code></pre> <p>What is the correct TastyPIE way, of making changes so I can get a loop of <code>ArticleBody</code> into my <code>NewsResource</code>?</p>
    singulars
    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.
 

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