Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 rest_framework import status [ from rest_framework import status] | |
from rest_framework.decorators import api_view [ from rest_framework.decorators import api_view] | |
from rest_framework.response import Response [ from rest_framework.response import Response] | |
from snippets.models import Snippet | |
from snippets.serializers import SnippetSerializer | |
@api_view(['GET', 'POST']) | |
def snippet_list(request): | |
""" |
This file contains 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.http import HttpResponse, JsonResponse | |
from django.views.decorators.csrf import csrf_exempt | |
from rest_framework.renderers import JSONRenderer | |
from rest_framework.parsers import JSONParser | |
from snippets.models import Snippet | |
from snippets.serializers import SnippetSerializer | |
@csrf_exempt | |
def snippet_list(request): | |
""" |
This file contains 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 snippets.models import Snippet | |
from snippets.serializers import SnippetSerializer | |
from django.http import Http404 | |
from rest_framework.views import APIView | |
from rest_framework.response import Response | |
from rest_framework import status [ from rest_framework import status] | |
class SnippetList(APIView): | |
""" |
This file contains 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 snippets.models import Snippet | |
from snippets.serializers import SnippetSerializer | |
from rest_framework import mixins [ from rest_framework import mixins] | |
from rest_framework import generics [ from rest_framework import generics] | |
class SnippetList(mixins.ListModelMixin, | |
mixins.CreateModelMixin, | |
generics.GenericAPIView): | |
queryset = Snippet.objects.all() | |
serializer_class = SnippetSerializer |
This file contains 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 snippets.models import Snippet | |
from snippets.serializers import SnippetSerializer | |
from rest_framework import generics | |
class SnippetList(generics.ListCreateAPIView): | |
queryset = Snippet.objects.all() | |
serializer_class = SnippetSerializer | |
This file contains 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 PollManager(models.Manager): | |
def with_counts(self): | |
from django.db import connection | |
with connection.cursor() as cursor: | |
cursor.execute(""" | |
SELECT p.id, p.question, p.poll_date, COUNT(*) | |
FROM polls_opinionpoll p, polls_response r | |
WHERE p.id = r.poll_id |
This file contains 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.contrib.auth.models import User | |
from .managers import PersonManager | |
class Person(User): | |
objects = PersonManager() | |
class Meta: | |
proxy = True | |
ordering = ('first_name', ) |
This file contains 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 | |
from django.contrib.auth.models import User | |
class Profile(models.Model): | |
user = models.OneToOneField(User, on_delete=models.CASCADE) | |
bio = models.TextField(max_length=500, blank=True) | |
location = models.CharField(max_length=30, blank=True) | |
birth_date = models.DateField(null=True, blank=True) | |
This file contains 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 __future__ import unicode_literals | |
from django.db import models | |
from django.core.mail import send_mail | |
from django.contrib.auth.models import PermissionsMixin | |
from django.contrib.auth.base_user import AbstractBaseUser | |
from django.utils.translation import ugettext_lazy as _ | |
from .managers import UserManager |
OlderNewer