Пример #1
0
    async def _execute(self) -> MODEL:
        instance_list = await self.queryset

        if not instance_list:
            raise DoesNotExist("Object does not exist")

        if len(instance_list) == 1:
            return instance_list[0]

        raise MultipleObjectsReturned(
            "Multiple objects returned, expected exactly one")
Пример #2
0
    async def _execute(self) -> Optional[MODEL]:
        instance_list = await self.queryset

        if not instance_list:
            return None

        if len(instance_list) == 1:
            return instance_list[0]

        raise MultipleObjectsReturned(
            "Multiple objects returned, expected exactly one")
Пример #3
0
 async def _execute(self) -> List[MODEL]:
     instance_list = await self._db.executor_class(
         model=self.model,
         db=self._db,
         prefetch_map=self._prefetch_map,
         prefetch_queries=self._prefetch_queries,
     ).execute_select(self.query, custom_fields=list(self._annotations.keys()))
     if self._single:
         if len(instance_list) == 1:
             return instance_list[0]
         if not instance_list:
             if self._raise_does_not_exist:
                 raise DoesNotExist("Object does not exist")
             return None  # type: ignore
         raise MultipleObjectsReturned("Multiple objects returned, expected exactly one")
     return instance_list
Пример #4
0
 async def _execute(self):
     self.query = self._make_query()
     instance_list = await self._db.executor_class(
         model=self.model,
         db=self._db,
         prefetch_map=self._prefetch_map,
         prefetch_queries=self._prefetch_queries,
     ).execute_select(self.query,
                      custom_fields=list(self._annotations.keys()))
     if not instance_list:
         if self._get:
             raise DoesNotExist('Object does not exist')
         if self._single:
             return None
         return []
     elif self._get:
         if len(instance_list) > 1:
             raise MultipleObjectsReturned(
                 'Multiple objects returned, expected exactly one')
         return instance_list[0]
     elif self._single:
         return instance_list[0]
     return instance_list