Created
September 24, 2020 01:29
-
-
Save toxinu/28c57a79a60b5cd9ff51db96ae625fa2 to your computer and use it in GitHub Desktop.
blog/restless-for-building-python-restful-api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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