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
# viewsets.py | |
from rest_framework.decorators import api_view, permission_classes | |
from django.http import FileResponse | |
from django.shortcuts import get_object_or_404 | |
@api_view(['GET']) | |
@permission_classes((IsAuthenticated,)) | |
def download(file): |
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
# Contar total de itens em dicionários em uma lista | |
nomes = [] | |
total = [] | |
usuario = {} | |
lista = [{'user': 'João', 'idade': 25}, {'user': 'Maria', 'idade': 22}, {'user': 'João', 'idade': 33}] | |
for item in lista: | |
if not item.get('user') in nomes: | |
nomes.append(item.get('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
class SerializerDaFK(serializers.ModelSerializer): | |
""" Serializer com Fields Específicos """ | |
class Meta: | |
model = NomeDoModeldaFK | |
fields = ('id', | |
'campo1', | |
'campo2') | |
class SerializerPrincipal(serializers.ModelSerializer): |