Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Get Autogenerated Serializers and API EndPoints
- django
- djangorestframework
Tested with all Django versions from `1.8.x to 2.x.x`
Django
.For Django==1.8.x
- djangorestframework==3.4.2
autogenerated-api built for django.
pip install autogenerated_api
django_app architecture looks like
- app_name
- __init__.py
- admin.py
- models.py
- serializers.py
- tests.py
- views.py
from .models import ModelName
from autogenerated_api.serializers import DeadlySerializerFactory
ModelNameDeadlySerializer = DeadlySerializerFactory(modelName)
- DeadlySerializerFactory `Optional Paramaters`
- nest = ["field_1","field_2"]
- nested_fields = {"field_name_in_releation" : ["related_model_field_1","related_model_field_2"]}
- if you want to get all fields of model while is in relation
- nested_fields = {"field_name_in_reletion" : ["*"]}
- exclude = ["field_1","field_2"] : fields that you want to exclude
ModelNameDeadlySerializer = DeadlySerializerFactory(modelName,nest,nested_fields,exclude)
import app_name.models
import app_name.serializers
from autogenerated_api.autogeneration import make_all_viewsets
make_all_viewsets(__name__)
api_urls.py
in main project folder.Main project folder Architecture
- main_proj_name
- __init__.py
- settings.py
- urls.py
- wsgi.py
- api_urls.py
api_urls.py
file.import app_name.views
from django.urls import path, re_path , include
from autogenerated_api import autogenerated_urls
urlpatterns = autogenerated_urls.urlpatterns
urlpatterns += []
Add the Below urls.py
import django
dj_version = django.get_version()
from django.contrib import admin
try:
from django.urls import path, include , re_path
except ImportError:
from django.conf.urls import include, url
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse
import re
if re.search('^2[\d.]+',str(dj_version)):
urlpatterns = [
re_path(r'^api/', include(('main_proj_name.api_urls', 'main_proj_name') , namespace="api")),
]
else:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include('main_proj_name.api_urls' , namespace="api")),
]
AUTOGENERATE_APPS = ["app_name"]
- Autogenerated End Points
- `/api/model_name_in_lower/` : list out all the model_instance
- `/api/model_name_in_lower/<instance_id>` : you will get detail of instance of given id
Through autogenerated_api
module , you can directly create serializers coresponding to each model and can also access the all fields value of model which are in relation (m2m or foreignkey relationship)
.
To get the list of model instance , You have to write an api end points , like ListAPiView
and for getting the detail of model instance, have to implement DetailAPIView or RetrieveApiView
end points.
Now , You don't have to create these APi-end points and get worry about the serailizers . This module will take care. Just , follow the steps that i mentioned above.
- Module with more functionality and more autogenerated end points.
I will really appreciate if you support the project by clicking the star button on Github repository
FAQs
Get Autogenerated Serializers and APi End Points
We found that autogenerated-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.