def get_model(cls):
"""
Returns the model class
"""
model = None
with suppress(AttributeError, InvalidRequestError):
model = cls.queryset._only_entity_zero().class_
if model:
return model
with suppress(AttributeError):
model = cls.serializer_class.Meta.model
assert model is not None, (
"Couldn't figure out the model for {viewset} attribute, either provide a"
'queryset or a serializer with a Meta.model'.format(viewset=cls.__name__)
)
return model
评论列表
文章目录