Skip to content

Instantly share code, notes, and snippets.

@1844144
Last active January 4, 2019 13:59
Show Gist options
  • Save 1844144/bc62815c8bcfccbbbd1e8a5b432c36da to your computer and use it in GitHub Desktop.
Save 1844144/bc62815c8bcfccbbbd1e8a5b432c36da to your computer and use it in GitHub Desktop.
# It was helpful for me when I have to provide
for class_name in models.autogenerate:
serializer_name = class_name+'Serializer'
view_name = class_name+'SetAuto'
globals()[view_name] = type(
view_name,
(viewsets.ModelViewSet,),
{
'queryset': getattr(models, class_name).objects.all(),
'serializer_class' : getattr(serializers, serializer_name)
}
)
globals()[class_name+'_list']=globals()[view_name].as_view(view.as_list)
globals()[class_name+'_detail']=globals()[view_name].as_view(view.as_detail)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment