Package: drf_auto_endpoint
# LevIT's DRF Auto-endpoint`drf_auto_endpoint` is a library used to make it as straight-forward to declare an API endpointas it is to declare a new `ModelAdmin` in Django.## InstallationSo far, `drf_auto_endpoint` is only compatible with python 3.5, Django 1.9 and DRF 3.3.It probably also works with other version of python 3.3+ and Django 1.8+, it just hasn't beentested with those yet.### With pip`pip install drf_auto_endpoint`### From sourceWithin the source directory:`python setup.py install`## UsageFirst of all you'll need to import the default EndpointRouter in your urls.py file.`from drf_auto_endpoint.router import router`As well as add its urls to your `urlpatterns` in `urls.py`, the same way you would with DRF's`DefaultRouter`.```urlpatterns = [...url(r'^api/', include(router.urls)),...]```### PrototypingThe quickest way to get a working endpoint is to register a model with the router. Register acceptsan optional keyword argument for the `url` associated to that endpoint. By default the url for anendpoint willbe `app_label/verbose_name_plural````from drf_auto_endpoint.router import routerfrom my_app.models import MyModel, OtherModelrouter.register(MyModel)router.register(OtherModel, url='my_custom_url')urlpatterns = [url(r'^api/', include(router.urls)),]```#### OptionsWhen registering a Model with the router, you can also pass several keyword arguments:- `read_only`: Boolean, indicates whether this endpoint should be read_only or not- `fieldsets`: a tuple containing the list of fieldsets to use. A fieldset has 2 properties,a `title` and a list of `fields` (by default, every field from the model will be used).- `filter_fields`: a tuple containing a list of fields on which the endpoint will accept filtering- `search_fields`: a tuple containing a list of fields on which the endpoint will accept searching(text fields only)- `ordering_fields`: a tuple containing a list of fields on which the endpoint will accept ordering- `page_size`: the number of records to render at once (automatically activates pagination)- `permission_classes`: a tuple containing the list of DRF permission classes to use- `url`: the base url for the viewset- `viewset`: the viewset class to use instead of the auto-generated one- `base_viewset`: a base viewset class to use instead of the defaults (`ModelViewSet` or`ReadOnlyModelViewSet`)### Custom Enpoint'sAs with Django's `ModelAdmin` class you can also define your own `Endpoint` class and register itwith the router instead of registering a model.```# my_app/endpoints.pyfrom drf_auto_endpoint.endpoints import Endpointfrom .models import MyModelclass MyModelEndpoint(Endpoint):model = MyModelread_only = Truefields = ('id', 'name', 'category')``````# urls.pyfrom drf_auto_endpoint.router import routerfrom my_app.endpoints import MyModelEndpointrouter.register(endpoint=MyModelEndpoint)urlpatterns = [url(r'^api/', include(router.urls)),]```## MetaDataThis package also provides an `AutoMetadata` and a `MinimalAutoMetadata` class. Thoseclasses can be used in place of the default DRF metadata class.To use it, change you DRF settings to include```REST_FRAMEWORK = {'DEFAULT_METADATA_CLASS': 'drf_auto_endpoint.metadata.AutoMetadata',}```Those MetaData classes will provide extra information about the fields provided by theserializer and hint the client application on how to use and display those fields.As an example, see the extra output these classes provide for the sample model `Product`.```"fields": [{"read_only": true,"name": "id","label": "Id","widget": "number","extra": {}},{"read_only": false,"name": "name","label": "Name","widget": "text","extra": {}},{"read_only": false,"name": "category","label": "Category","widget": "foreignkey","extra": {"related_model": "sample/category"}},{"read_only": false,"name": "product_type","label": "Product_Type","widget": "select","extra": {"choices": [{"value": "s","label": "Sellable"},{"value": "r","label": "Rentable"}]}},{"read_only": true,"name": "__str__","label": "Product","widget": "text","extra": {}}],"list_display": ["__str__"],"filter_fields": [],"search_enabled": false,"ordering_fields": [],"needs": [{"singular": "category","app": "sample","plural": "categories"}],"fieldsets": [{"title": null,"fields": [{"name": "name"},{"name": "category"},{"name": "product_type"}]}]```## ToDo- [ ] Python 2.7 compatibility- [x] Python 3.4 compatibility- [ ] Django 1.10 compatibility- [ ] Write better documentation- [x] Provide a wrapper for `ModelSerializer` and `ModelViewSet`- [x] Add custom options for filter, search and order- [ ] Enable admin-like registration mechanism- [x] Provide a `Metadata` class to provide meta-information (like list_display) on `OPTION` calls- [x] Add `choices` (only for non-foreign-keys) and `related_model` to the `Metadata` class- [ ] Add languages information when django-model-translation is installed---License information available [here](LICENSE.md).Contributors code of conduct is available [here](COC.md). Note that this COC **will** be enforced.