# Path: products/models.py
# class Product(models.Model):
#     name = models.CharField(max_length=30)
#     race = models.ForeignKey(Race, null=True, related_name='race')
#     seller = models.ForeignKey(UserDetail, null=False)
#     gender = models.CharField(max_length=3, choices=GENDERS, default='NON')
#     sterile = models.BooleanField(default=False)
#     description = models.CharField(max_length=250, default='')
#     state = models.ForeignKey(State, null=True, default=1)
#     price = models.FloatField(null=False, default=0)
#     category = models.ForeignKey(Category)
#     active = models.BooleanField(null=False, default=True)
#     location = models.PointField(null=False)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def _get_latitude(self):
#         return str(self.location.y)
#     latitude = property(_get_latitude)
# 
#     def _get_longitude(self):
#         return str(self.location.x)
#     longitude = property(_get_longitude)
# 
#     def _get_race_id(self):
#         return str(self.race.id)
#     raceid = property(_get_race_id)
# 
#     def _get_state_id(self):
#         return str(self.state.id)
#     stateid = property(_get_state_id)
# 
#     def _get_category_id(self):
#         return str(self.category.id)
#     categoryid = property(_get_category_id)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: transactions/models.py
# class Transaction(models.Model):
#     product = models.ForeignKey(Product)
#     seller = models.ForeignKey(User, related_name='user_seller')
#     buyer = models.ForeignKey(User, related_name='user_buyer')
#     date_transaction = models.DateTimeField(auto_now_add=True)
# 
#     def __unicode__(self):
#         return self.product.name
# 
#     def __str__(self):
#         return self.product.name
# 
# Path: transactions/permissions.py
# class TransactionPermission(BasePermission):
#     def has_permission(self, request, view):
# 
#         if request.user.is_authenticated() and view.action in ('list', 'retrieve', 'create'):
#             return True
#         else:
#             return False
# 
#     def has_object_permission(self, request, view, obj):
# 
#         return request.user.is_superuser or request.user == obj.seller or request.user == obj.buyer
# 
# Path: transactions/serializers.py
# class TransactionsListSerializer(serializers.ModelSerializer):
# 
#     seller = serializers.StringRelatedField()
#     product = serializers.StringRelatedField()
#     buyer = serializers.StringRelatedField()
# 
#     class Meta:
#         model = Transaction
# 
# Path: transactions/serializers.py
# class TransactionsSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = Transaction
#         fields = ('id', 'product')


from django.db.models import Q
from django.shortcuts import get_object_or_404
from products.models import Product
from rest_framework import status
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from transactions.models import Transaction
from transactions.permissions import TransactionPermission
from transactions.serializers import TransactionsListSerializer
from transactions.serializers import TransactionsSerializer


class TransactionsViewSet(GenericViewSet):

    serializer_class = TransactionsSerializer
    permission_classes = (TransactionPermission,)

# Path: products/models.py
# class Product(models.Model):
#     name = models.CharField(max_length=30)
#     race = models.ForeignKey(Race, null=True, related_name='race')
#     seller = models.ForeignKey(UserDetail, null=False)
#     gender = models.CharField(max_length=3, choices=GENDERS, default='NON')
#     sterile = models.BooleanField(default=False)
#     description = models.CharField(max_length=250, default='')
#     state = models.ForeignKey(State, null=True, default=1)
#     price = models.FloatField(null=False, default=0)
#     category = models.ForeignKey(Category)
#     active = models.BooleanField(null=False, default=True)
#     location = models.PointField(null=False)
#     created_at = models.DateTimeField(auto_now_add=True)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     def _get_latitude(self):
#         return str(self.location.y)
#     latitude = property(_get_latitude)
# 
#     def _get_longitude(self):
#         return str(self.location.x)
#     longitude = property(_get_longitude)
# 
#     def _get_race_id(self):
#         return str(self.race.id)
#     raceid = property(_get_race_id)
# 
#     def _get_state_id(self):
#         return str(self.state.id)
#     stateid = property(_get_state_id)
# 
#     def _get_category_id(self):
#         return str(self.category.id)
#     categoryid = property(_get_category_id)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.name
# 
# Path: transactions/models.py
# class Transaction(models.Model):
#     product = models.ForeignKey(Product)
#     seller = models.ForeignKey(User, related_name='user_seller')
#     buyer = models.ForeignKey(User, related_name='user_buyer')
#     date_transaction = models.DateTimeField(auto_now_add=True)
# 
#     def __unicode__(self):
#         return self.product.name
# 
#     def __str__(self):
#         return self.product.name
# 
# Path: transactions/permissions.py
# class TransactionPermission(BasePermission):
#     def has_permission(self, request, view):
# 
#         if request.user.is_authenticated() and view.action in ('list', 'retrieve', 'create'):
#             return True
#         else:
#             return False
# 
#     def has_object_permission(self, request, view, obj):
# 
#         return request.user.is_superuser or request.user == obj.seller or request.user == obj.buyer
# 
# Path: transactions/serializers.py
# class TransactionsListSerializer(serializers.ModelSerializer):
# 
#     seller = serializers.StringRelatedField()
#     product = serializers.StringRelatedField()
#     buyer = serializers.StringRelatedField()
# 
#     class Meta:
#         model = Transaction
# 
# Path: transactions/serializers.py
# class TransactionsSerializer(serializers.ModelSerializer):
# 
#     class Meta:
#         model = Transaction
#         fields = ('id', 'product')


# Path: transactions/api.py
from django.db.models import Q
from django.shortcuts import get_object_or_404
from products.models import Product
from rest_framework import status
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from transactions.models import Transaction
from transactions.permissions import TransactionPermission
from transactions.serializers import TransactionsListSerializer
from transactions.serializers import TransactionsSerializer



class TransactionsViewSet(GenericViewSet):

    serializer_class = TransactionsSerializer
    permission_classes = (TransactionPermission,)

    queryset = Transaction.objects.filter()