Last active
October 21, 2017 11:04
-
-
Save guilatrova/346ad9eef0fd10d0de28eefbc6375051 to your computer and use it in GitHub Desktop.
LatrovaCommits DRF Tests 1.1
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 | |
from django.contrib.auth.models import User | |
class Transaction(models.Model): | |
description = models.CharField(max_length=100) | |
value = models.DecimalField(max_digits=5, decimal_places=2) | |
user = models.ForeignKey(User) |
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 rest_framework import serializers | |
from transactions.models import Transaction | |
class TransactionSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = Transaction | |
fields = ('id', 'description', 'value', 'user') |
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
... | |
# Application definition | |
INSTALLED_APPS = [ | |
'django.contrib.admin', | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.messages', | |
'django.contrib.staticfiles', | |
'rest_framework', | |
'transactions' | |
] | |
... |
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.shortcuts import render | |
from rest_framework import viewsets | |
from transactions.models import Transaction | |
from transactions.serializers import TransactionSerializer | |
class TransactionViewSet(viewsets.ModelViewSet): | |
queryset = Transaction.objects.all() | |
serializer_class = TransactionSerializer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment