Skip to main content

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.7.tar.gz (2.3 kB view hashes)

Uploaded Source

Built Distribution

manage_fields-0.0.7-py3-none-any.whl (2.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page