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
| $ tree . | |
| . | |
| ├── conftest.py | |
| ├── Makefile | |
| ├── MANIFEST.in | |
| ├── README.rst | |
| ├── setup.cfg | |
| ├── setup.py | |
| ├── src | |
| │ └── my_awesome_project |
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
| LOGIN_URL = 'https://localhost:8000/login' | |
| # Set these to drop to an unprivileged user after | |
| # binding the SMTP daemon (Default: False) | |
| DROP_PRIVILEGES_USER = False | |
| # Product name appear in email templates and optouts pages | |
| PRODUCT_NAME = 'My Awesome App' |
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
| [...] | |
| entry_points={ | |
| 'console_scripts': [ | |
| 'my-awesome-project = my_awesome_project.runner:main'] | |
| }, | |
| extras_require={ | |
| 'dev': [ | |
| 'bumpversion==0.5.3', | |
| 'docker-compose==1.9.0' | |
| ], |
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
| # src/my_awesome_project/runner/commands/version.py | |
| import click | |
| import django | |
| @click.command() | |
| def version(): | |
| "Show Django version." | |
| click.echo('Django {}'.format(django.__version__)) |
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 django.db import models | |
| class Pizza(models.Model): | |
| name = models.CharField(max_length=100) | |
| price = models.FloatField() | |
| is_vegetarian = models.BooleanField(default=False) | |
| class Ingredient(models.Model): |
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 .models import Pizza | |
| class PizzaResource(DjangoResource): | |
| preparer = FieldsPreparer(fields={ | |
| 'id': 'id', 'name': 'name'}) |
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
| class APIFilterMixin: | |
| allowed_fields_filter = [] | |
| def filter(self, queryset): | |
| filters = {} | |
| for arg in self.request.GET: | |
| if arg in self.allowed_fields_filter: | |
| filters.update({arg: self.request.GET.get(arg)}) | |
| return queryset.filter(**filters) |
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
| class PizzaResource(APIFilterMixin, DjangoResource): | |
| preparer = FieldsPreparer(fields={ | |
| 'id': 'id', 'name': 'name'}) | |
| allowed_fields_filter = [ | |
| 'name', 'name__startswith', | |
| 'price', 'price__lte', 'price__gte', | |
| 'ingredients__ingredient__name'] | |
| def list(self): | |
| qs = Pizza.objects.all() |
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
| class APIOrderingMixin: | |
| allowed_fields_ordering = [] | |
| ordering_field = 'order_by' | |
| def ordering(self, queryset): | |
| order_by = self.request.GET.get(self.ordering_field) | |
| if not order_by: | |
| return queryset | |
| if order_by.split('-')[-1] in self.allowed_fields_ordering: |
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
| class Country(models.Model): | |
| name = models.CharField(max_length=2) | |
| class Pizza(models.Model): | |
| name = models.CharField(max_length=255) | |
| country = models.ForeignKey(Country) |