Serializer which will automatically prefetch and bypass lazy calls
Project description
QuerysetSerializer
This package adds a serializer to ensure all models in the serializers get properly prefetched or selected
installation
pip install queryset-serializer
Usage
Simply install the package into your project and import the serializer
from queryset_serializer import QuerySetSerializer
class MyModelSerializer(QuerySetSerializer):
...
class Meta:
...
In order to prefetch/select everything make sure all serializers used are of QuerySetSerializer
Note : You cannot mix restframework.serializer.ModelSerializer
with this class
(However all instance of ModelSerializer should be replaceable)
Config
configurations can be changed as following:
from queryset_serializer.serializers import Config
Config.meta_class.{setting} = {new_value}
these are the relevant settings :
- prefetch_to_attr_prefix , What string will be used as prefix.
- prefetch_listing , How the prefetch is done (Options: PrefetchToAttrSerializerList, PrefetchSerializerList)
prefetch_listing
there are 2 options for the prefetch_listing. (Located in queryset_serializer.serializers.model
)
PrefetchToAttrSerializerList
will prefetch/select relations and use theto_attr
attribute of thePrefetch
classPrefetchSerializerList
will only prefetch/select relations
This package by default makes use PrefetchToAttrSerializerList,
The benefit of this is that the .all()
calls on the relations are nog longer lazy.
This can significantly speed up performance especially on a queryset with a large amount of results or if there are a lot of child (queryset)serializer
This can also be turned off, and instead do a regular prefetch:
from queryset_serializer.serializers import Config
from queryset_serializer.serializers.model import PrefetchSerializerList
Config.meta_class.prefetch_listing = PrefetchSerializerList
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for queryset-serializer-1.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 235c8315a7c0b13e1cba5ddf6d7fee1a117598b27c5c2ef042a299b390349555 |
|
MD5 | a165a0ad6bf6dca5021f72ae287ea2da |
|
BLAKE2b-256 | 3851ad887bcace3ab4784504cfc208b0d7bd57c7d275e6c878aab1b4c604ded7 |
Hashes for queryset_serializer-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1faf64548e36f17c0fcee0cde3897a2bf183dcbf0f50e702e8fa23edbc226669 |
|
MD5 | 654cf39bfe22185e32cd755dd2c9709f |
|
BLAKE2b-256 | 27bb98f9d7562ae94082b1798379c9c69b8e4b82109a9f3974254928d9d8fa09 |