Manage fields by request params
Project description
Manage fields
Usage
views.py
from manage_fields.mixins import MFViewMixin
class MyView(MFViewMixin, ...):
serializer_class = MySerializer
....
serializers.py
from manage_fields.mixins import MFSerializerMixin
class MySerializer(MFSerializerMixin, ...):
...
Request
https://abcd.com/?allow_fields={id,name}
Params
allow_fields
- Fields returned in response
disallow_fields
- Fields that are not returned in the response
Example
models.py
class Example(models.Model):
field1 = models.CharField(max_length=50)
field2 = models.TextField()
field3 = models.IntegerField()
Request
https://example.com/?allow_fields={id,field1}
Response
[
{
"id": 1,
"field1": "Field1 value 1"
},
{
"id": 2,
"field1": "Field1 value 2"
}
]
Request
https://example.com/?disallow_fields={id,field1}
Response
[
{
"field2": "Field2 value 1",
"field3": "Field3 value 1"
},
{
"field2": "Field2 value 2",
"field3": "Field3 value 2"
}
]
Also you can use this package for CreateAPIView
, UpdateAPIView
, RetrieveAPIView
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
manage-fields-0.0.6.tar.gz
(2.2 kB
view hashes)
Built Distribution
Close
Hashes for manage_fields-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1693bbfa23d93c617f436616e4044ceb2b224aab043c65c49c5f1e38f7eb394 |
|
MD5 | a3f618cd9e9a40239ef14ef4a33cdd2b |
|
BLAKE2b-256 | 9994d8431e86965ceac64e190e3a51b0290c994eb74a0491395dca1a49831ac7 |