# Path: races/models.py
# class Race(models.Model):
# 
#     name = models.CharField(max_length=40)
#     active = models.BooleanField(default=True)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: races/permissions.py
# class RacesPermission(BasePermission):
# 
#     def has_permission(self, request, view):
# 
#         if view.action in ['list', 'metadata']:
#             return True
#         else:
#             return request.user.is_authenticated() and request.user.is_admin()
# 
# Path: races/serializers.py
# class RacesSerializer (serializers.ModelSerializer):
# 
#     class Meta:
#         model = Race
#         fields = ('id', 'name')


import datetime
from rest_framework import status
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from races.models import Race
from races.permissions import RacesPermission
from races.serializers import RacesSerializer



class RacesViewSet(GenericViewSet):

    permission_classes = [RacesPermission]
    queryset = Race.objects.filter(active=1)

# Path: races/models.py
# class Race(models.Model):
# 
#     name = models.CharField(max_length=40)
#     active = models.BooleanField(default=True)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: races/permissions.py
# class RacesPermission(BasePermission):
# 
#     def has_permission(self, request, view):
# 
#         if view.action in ['list', 'metadata']:
#             return True
#         else:
#             return request.user.is_authenticated() and request.user.is_admin()
# 
# Path: races/serializers.py
# class RacesSerializer (serializers.ModelSerializer):
# 
#     class Meta:
#         model = Race
#         fields = ('id', 'name')


# Path: races/api.py
import datetime
from rest_framework import status
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from races.models import Race
from races.permissions import RacesPermission
from races.serializers import RacesSerializer




class RacesViewSet(GenericViewSet):

    permission_classes = [RacesPermission]
    queryset = Race.objects.filter(active=1)

    serializer_class = RacesSerializer