# Path: web/carontepass/access/models.py
# class Device(models.Model):
#     __tablename__ = 'cp_device'
#     
#     NFC = 'nfc'
#     MAC = 'mac'
#     TAG = 'tag'
#     DEVICE_CHOICES = (
#         (NFC, 'NFC'),
#         (MAC, 'MAC'),
#         (TAG, 'TAG'),
#     )
# 
#     user = models.ForeignKey(User)
#     kind = models.CharField(max_length=3,
#                                       choices=DEVICE_CHOICES,
#                                       default=NFC,
#                                       blank=False,
#                                       )
#     code = models.CharField(max_length=64, blank=False)
#     
#     def __str__(self):
#         return 'Device {}:{} - {}'.format(self.user, self.kind, self.code)
#         
#     @staticmethod   
#     def check_exists_device(code_id):
#         #If there is no device code creates a new one.
#         #With this you have saved the new devices and then assign them to your user.
#         
#         if not Device.objects.filter(code=code_id):
#             caronte = User.objects.filter(username="caronte").first()
#             device_create = Device.objects.create(user=caronte, kind='tag', code=code_id)
# 
# Path: web/carontepass/access/serializers.py
# class UserSerializer(serializers.ModelSerializer):
#     class Meta:
#             model = User
#             fields = ('id', 'name', 'rol')
# 
# class DeviceSerializer(serializers.ModelSerializer):
#     class Meta:
#             model = Device
#             fields = ('id', 'user', 'kind', 'code')


from rest_framework import viewsets
from django.contrib.auth.models import User
from .models import Device
from .serializers import UserSerializer, DeviceSerializer

 
class UserViewSet(viewsets.ModelViewSet):
 
    serializer_class = UserSerializer
    queryset = User.objects.all()


class DeviceViewSet(viewsets.ModelViewSet):
 
    serializer_class = DeviceSerializer

# Path: web/carontepass/access/models.py
# class Device(models.Model):
#     __tablename__ = 'cp_device'
#     
#     NFC = 'nfc'
#     MAC = 'mac'
#     TAG = 'tag'
#     DEVICE_CHOICES = (
#         (NFC, 'NFC'),
#         (MAC, 'MAC'),
#         (TAG, 'TAG'),
#     )
# 
#     user = models.ForeignKey(User)
#     kind = models.CharField(max_length=3,
#                                       choices=DEVICE_CHOICES,
#                                       default=NFC,
#                                       blank=False,
#                                       )
#     code = models.CharField(max_length=64, blank=False)
#     
#     def __str__(self):
#         return 'Device {}:{} - {}'.format(self.user, self.kind, self.code)
#         
#     @staticmethod   
#     def check_exists_device(code_id):
#         #If there is no device code creates a new one.
#         #With this you have saved the new devices and then assign them to your user.
#         
#         if not Device.objects.filter(code=code_id):
#             caronte = User.objects.filter(username="caronte").first()
#             device_create = Device.objects.create(user=caronte, kind='tag', code=code_id)
# 
# Path: web/carontepass/access/serializers.py
# class UserSerializer(serializers.ModelSerializer):
#     class Meta:
#             model = User
#             fields = ('id', 'name', 'rol')
# 
# class DeviceSerializer(serializers.ModelSerializer):
#     class Meta:
#             model = Device
#             fields = ('id', 'user', 'kind', 'code')


# Path: web/carontepass/access/viewsets.py
from rest_framework import viewsets
from django.contrib.auth.models import User
from .models import Device
from .serializers import UserSerializer, DeviceSerializer


 
class UserViewSet(viewsets.ModelViewSet):
 
    serializer_class = UserSerializer
    queryset = User.objects.all()


class DeviceViewSet(viewsets.ModelViewSet):
 
    serializer_class = DeviceSerializer

    queryset = Device.objects.all()