Source

article / article / api / views.py

Full commit
from tastypie.resources import ModelResource
from tastypie import fields, utils

from article.models import Recipe, Ingredient, RecipeIngredient, Measurement, Post


class RecipeResource(ModelResource):
    ingredients = fields.ToManyField('article.api.views.RecipeIngredientResource', 'recipe_ingred', related_name='recipeingredient', full=True)

    class Meta:
        queryset = Recipe.active.select_related()
        resource_name = 'recipe'

class IngredientResource(ModelResource):
    class Meta:
        queryset = Ingredient.objects.all()

class RecipeIngredientResource(ModelResource):
    ingred_name = fields.ToOneField('article.api.views.IngredientResource', 'ri_ingred', full=True)
    measurement = fields.ToOneField('article.api.views.MeasurementResource', 'ri_measurement', full=True, null=True)

    class Meta:
        queryset = RecipeIngredient.objects.all()
        resource_name = 'recipeingredient'
        excludes = ['ri_date']

class MeasurementResource(ModelResource):
    class Meta:
        queryset = Measurement.objects.all()

class FAQResource(ModelResource):
    class Meta:
        queryset = Post.active.filter(post_type=3)
        resource_name = 'faq'
        excludes = ['is_published', 'published_on', 'post_image', 
                    'post_excerpt', 'post_enable_comments', 
                    'post_date_lastmod', 'post_date_create']

class PostResource(ModelResource):
    class Meta:
        queryset = Post.active.filter(post_tags__icontains="FAQ")
        resource_name = 'post'
        excludes = ['post_content', 'is_published', 'post_date_create', 
                    'post_date_lastmod', 'post_image', 'post_enable_comments']