# Path: saveserches/models.py
# class SavedSearch(models.Model):
#     user = models.ForeignKey(User)
#     keywords = models.CharField(max_length=80)
#     longitude = models.FloatField(null=True)
#     latitude = models.FloatField(null=True)
#     category = models.ForeignKey(Category)
#     race = models.ForeignKey(Race)
#     name = models.CharField(max_length=60)
# 
#     def __unicode__(self):
#         return self.keywords
# 
# Path: saveserches/permissions.py
# class SaveSearchesPermission(BasePermission):
#     def has_permission(self, request, view):
#         if request.user.is_authenticated() and view.action in ('list', 'retrieve', 'create', 'destroy'):
#             return True
#         elif view.action == 'metadata':
#             return True
#         else:
#             return False
# 
#     def has_object_permission(self, request, view, obj):
# 
#         return request.user.is_superuser or request.user == obj.user
# 
# Path: saveserches/serializers.py
# class SaveSearchesSerializer (serializers.ModelSerializer):
# 
#     class Meta:
#         model = SavedSearch
# 
# class SaveSearchesListSerializer (serializers.ModelSerializer):
# 
#     category = serializers.StringRelatedField()
#     race = serializers.StringRelatedField()
# 
#     class Meta:
#         model = SavedSearch
#         fields = ('id', 'name', 'keywords', 'category', 'latitude', 'longitude', 'race')


from rest_framework.viewsets import ModelViewSet
from saveserches.models import SavedSearch
from saveserches.permissions import SaveSearchesPermission
from saveserches.serializers import SaveSearchesSerializer, SaveSearchesListSerializer

class SaveSearchesViewSet (ModelViewSet):

    serializer_class = SaveSearchesSerializer
    permission_classes = (SaveSearchesPermission,)

    def get_queryset(self):
        return SavedSearch.objects.filter(user=self.request.user)

    def get_serializer_class(self):
        if self.action in ('list', 'retrieve'):

# Path: saveserches/models.py
# class SavedSearch(models.Model):
#     user = models.ForeignKey(User)
#     keywords = models.CharField(max_length=80)
#     longitude = models.FloatField(null=True)
#     latitude = models.FloatField(null=True)
#     category = models.ForeignKey(Category)
#     race = models.ForeignKey(Race)
#     name = models.CharField(max_length=60)
# 
#     def __unicode__(self):
#         return self.keywords
# 
# Path: saveserches/permissions.py
# class SaveSearchesPermission(BasePermission):
#     def has_permission(self, request, view):
#         if request.user.is_authenticated() and view.action in ('list', 'retrieve', 'create', 'destroy'):
#             return True
#         elif view.action == 'metadata':
#             return True
#         else:
#             return False
# 
#     def has_object_permission(self, request, view, obj):
# 
#         return request.user.is_superuser or request.user == obj.user
# 
# Path: saveserches/serializers.py
# class SaveSearchesSerializer (serializers.ModelSerializer):
# 
#     class Meta:
#         model = SavedSearch
# 
# class SaveSearchesListSerializer (serializers.ModelSerializer):
# 
#     category = serializers.StringRelatedField()
#     race = serializers.StringRelatedField()
# 
#     class Meta:
#         model = SavedSearch
#         fields = ('id', 'name', 'keywords', 'category', 'latitude', 'longitude', 'race')


# Path: saveserches/api.py
from rest_framework.viewsets import ModelViewSet
from saveserches.models import SavedSearch
from saveserches.permissions import SaveSearchesPermission
from saveserches.serializers import SaveSearchesSerializer, SaveSearchesListSerializer


class SaveSearchesViewSet (ModelViewSet):

    serializer_class = SaveSearchesSerializer
    permission_classes = (SaveSearchesPermission,)

    def get_queryset(self):
        return SavedSearch.objects.filter(user=self.request.user)

    def get_serializer_class(self):
        if self.action in ('list', 'retrieve'):

            return SaveSearchesListSerializer