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.
Metadata
Release files for drfwn-quick 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drfwn_quick-0.1.0.tar.gz | 6.4 kB | Without provenance | Details for drfwn_quick-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drfwn_quick-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for drfwn_quick-0.1.0-py3-none-any.whl |
Total release size: 14.5 kB
Release files / drfwn_quick-0.1.0.tar.gz
| Download URL | drfwn_quick-0.1.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17e5a0615992cf359a5b7f409f56eab3e5336e9a0d3f04b555a286c546e69fc9
|
|
BLAKE2b-256 checksum How to use checksums |
2d087e27adfc3bfd663dbb17e9e83bd4620fb19a586ae2477c625d75af7056ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2
|
Release files / drfwn_quick-0.1.0-py3-none-any.whl
| Download URL | drfwn_quick-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2057926068facb8f6e154a8546e287e9924c8b7e114e035fdab30ed1f9ee0b1
|
|
BLAKE2b-256 checksum How to use checksums |
ba845c41b1e8de3acce50353c2678a666c865aefff779135173b66f8046d9c63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.12 Linux/5.15.133.1-microsoft-standard-WSL2
|
Security for drfwn-quick 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.