No project description provided
Project description
drfwn_quick
Handle full serialization of nested models quickly.
Overview
drfwn-quick
(django rest framework writable nested quick) extends drf-writable-nested
to allow nested models to be serialized rapidly with full data for relations
by taking advantage of django's queryset.values()
method.
Example API response with drfwn-quick
:
[
{
'id': 1,
'name': 'Beans',
'description': 'Some beans.',
'enabled': False,
'vendors': [
{
'id': 1,
'name': 'Beans Emporium',
'about': 'We sell beans.',
'enabled': False
}
]
}
]
Example without:
[
{
'id': 1,
'name': 'Beans',
'description': 'Some beans.',
'enabled': False,
'vendors': [1]
}
]
Note that without drfwn-quick
, the relational field "vendors"
is simply
a representation of database primary keys (IDs).
Features
Full Data
As seen in the overview above, responses with relations are looked-up to return complete data from the API call, not just IDs (primary keys).
Note that so long as DRFWN_QUICK_ALWAYS
is falsy, a url parameter is used to
control this behaviour. This means that the original serialization can remain
accessible by default, for things such as the DRF UI, if desired.
Performance
Data is built quickly by only accessing queryset.values()
for the object and
it's relation's querysets. Because this does not instsntiate Model objects for each
value within the queryset(s), it is significantly faster on larger datasets.
Timed Examples
Coming... :)
Writable
This is native to drf-writable-nested
but because drfwn-quick
extends it,
it's worth noting that the nested values are writable, and require only IDs
to do so.
However, note that a key difference between drf-writable-nested
alone and
drfwn-quick
is that the response after ceating or updating a value can be
fully contextual, if quick is enabled for that call/always.
Meaning, a POST
or PUT
request may have a payload with {..., "relation": [1, 3]}
but still yield {..., "relation": [{"id": 1, ...}, {"id": 3, ...}]}
.
settings.py
There are a few items that can be set via the local Django app's settings.py
file.
Setting | Default | About |
---|---|---|
DRFWN_QUICK_ALWAYS |
False |
If true, removed the need to pass a URL param to enable quick functionality. |
DRFWN_QUICK_DATETIME_FORMAT |
"%Y/%m/%d" |
The format to use for datetime.datetime serialisation. |
DRFWN_QUICK_HANDLE_DATETIMES |
True |
If true, serialise datetime.datetime objects. |
DRFWN_QUICK_URL_PAGE_PARAM_NAME |
"page_size" |
The URL parameter name to use for page size. |
DRFWN_QUICK_URL_QUICK_PARAM_NAME |
"quick" |
The URL parameter name to control quick functionality. |
Tests
Tests exist, if you want to contribute, please consider tests. There's always room for improvement on existing tests, too.
Coverage report will be added eventually.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file drfwn_quick-0.1.0.tar.gz
.
File metadata
- Download URL: drfwn_quick-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17e5a0615992cf359a5b7f409f56eab3e5336e9a0d3f04b555a286c546e69fc9 |
|
MD5 | 1052157f712c9ab92a4af383c2613c3f |
|
BLAKE2b-256 | 2d087e27adfc3bfd663dbb17e9e83bd4620fb19a586ae2477c625d75af7056ae |
File details
Details for the file drfwn_quick-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: drfwn_quick-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2057926068facb8f6e154a8546e287e9924c8b7e114e035fdab30ed1f9ee0b1 |
|
MD5 | 4d91688f0ebba8a3b4ca2d523f95072f |
|
BLAKE2b-256 | ba845c41b1e8de3acce50353c2678a666c865aefff779135173b66f8046d9c63 |