class RoomSerializer(serializers.ModelSerializer): typeroom = TypeRoomSerializer(required=False) area = AreaSerializer(required=False) class Meta: model = Room fields = ['id', 'name', 'number_now', 'typeroom', 'area', 'status']
class ProfileInListSerializer(serializers.ModelSerializer): position = PositionSerializer(required=False) area = AreaSerializer(required=False) class Meta: model = Profile fields = ['gender', 'phone', 'public_id', 'position', 'area']
class ProfileStaffListBillSerializer(serializers.ModelSerializer): area = AreaSerializer(required=False) position = PositionSerializer(required=False) user = UserSerializer(required=False) class Meta: model = Profile fields = ['user', 'gender', 'phone', 'public_id', 'area', 'position']
class RoomListSerializer(serializers.ModelSerializer): typeroom = TypeRoomSerializer(required=False) area = AreaSerializer(required=False) class Meta: model = Room fields = [ 'id', 'name', 'slug', 'number_now', 'typeroom', 'area', 'status', 'created_at', 'last_update' ]
def listAreas(request): try: areas = Areas.objects.all() if len(areas) > 0: areasSerializer = AreaSerializer(areas, many=True, context= {'request': request}) data = {'bodyObject': areasSerializer.data, 'result': 'ok', 'status':status.HTTP_200_OK } return data else: data = {'bodyObject':[], 'result': 'error','statusText': 'No existen Areas registradas','status':status.HTTP_200_OK } return data except Areas.DoesNotExist: data = {'bodyObject':[], 'result': 'error','statusText': 'Lo sentimos!! Ocurrio un error con tu sesion y no el sistema no puede mostrar la informacion.','status':status.HTTP_200_OK } return data
class RoomSerializer(serializers.ModelSerializer): created_by = UserSerializer(required=False) name = serializers.CharField(required=True) slug = serializers.CharField(required=False) number_now = serializers.CharField(required=True) # typeroom = TypeRoomSerializer(required=True) area = AreaSerializer(required=True) typeroom = TypeRoomSerializer(required=False) STATUS = Choices( ('A', _('Available')), ('F', _('Full')), ('UA', _('Unavailable')), ) status = serializers.ChoiceField(choices=STATUS, required=True) class Meta: model = Room fields = [ 'id', 'name', 'slug', 'number_now', 'typeroom', 'area', 'status', 'created_at', 'last_update', 'created_by' ] # Get current user login def _current_user(self): request = self.context.get('request', None) if request: return request.user return False def create(self, validated_data): try: current_user = self._current_user() model = Room.objects.create( name=validated_data['name'], number_now=validated_data['number_now'], typeroom=validated_data['typeroom'], area=validated_data['area'], status=validated_data['status'], created_at=validated_data['created_at'], last_update=validated_data['last_update'], created_by=current_user, ) model.save() return model except: return serializers.ValidationError("Error") return serializers.ValidationError("Server error")
class ProfileNhanVienSerializer(serializers.ModelSerializer): # faculty = FacultySerializer(required=False) position = PositionSerializer(required=False) area = AreaSerializer(required=False) # my_class = ClassSerializer(required=False) class Meta: model = Profile fields = [ 'birthday', 'address', 'identify_card', 'gender', 'phone', 'created_at', # 'faculty', # 'my_class', 'position', 'area', ]
class ProfileListSerializer(serializers.ModelSerializer): faculty = FacultySerializer(required=False) position = PositionSerializer(required=False) area = AreaSerializer(required=False) my_class = ClassSerializer(required=False) user = UserProfileListSerializer() class Meta: model = Profile fields = [ 'user', 'public_id', 'birthday', 'address', 'identify_card', 'gender', 'phone', 'created_at', 'faculty', 'my_class', 'position', 'area', ]