Manage fields by request params
Project description
Manage fields
settings.py
INSTALLED_APPS = [
...,
'manage_fields'
]
views.py
from manage_fields.mixins import MFViewMixin
class MyView(MFViewMixin, ...):
serializer_class = MySerializer
....
serializers.py
from manage_fields.mixins import MFSerializer
class MySerializer(MFSerializer, ...):
...
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.4.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for manage_fields-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ed660f08898235a5a659cd6e46b1f2283aef5a998e034f658019a38adf7e238 |
|
MD5 | 3cca886899b112645b202988b57a8b45 |
|
BLAKE2b-256 | 3645fd65cde39835e9b5120f3f45568468436a99f0b545d60fc402d8b61aaabd |