Skip to content

Instantly share code, notes, and snippets.

@toxinu
Created September 24, 2020 01:29
Show Gist options
  • Select an option

  • Save toxinu/28c57a79a60b5cd9ff51db96ae625fa2 to your computer and use it in GitHub Desktop.

Select an option

Save toxinu/28c57a79a60b5cd9ff51db96ae625fa2 to your computer and use it in GitHub Desktop.
blog/restless-for-building-python-restful-api
from restless.dj import DjangoResource
from restless.preparers import FieldsPreparer
from .mixins import APIPaginatorMixin
class CountryResource(APIPaginatorMixin, DjangoResource):
preparer = FieldsPreparer(fields={
'id': 'id',
'name': 'name'})
def get_queryset(self):
return Pizza.objects.all()
class PizzaResource(APIPaginatorMixin, DjangoResource):
preparer = FieldsPreparer(fields={
'id': 'id',
'name': 'name',
'country': 'country.id'})
def get_queryset(self):
return Country.objects.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment