Skip to content

[QUESTION] CBV Inheritance #2

@bgorges

Description

@bgorges

Description

How might I go about writing a CBV that can be inherited from? I want to make a generic class that just needs the class variables set to populate the default CRUD operations that are in the generic base class.

"First" attempt

cbv_router = APIRouter()

class GenericCBV:
    service: Optional[Service] = Depends(None)
    model: Optional[Vertex] = Depends(None)

    @property
    def model_id(self):
        return f'{self.model.vertex_label()}_id'

    @cbv_router.get('/')
    async def get_model_list(self):
        return self.service.get(self.model.vertex_label())
router = APIRouter()
router.include_router(cbv_router)

@cbv(router)
class InvalidationController(GenericCBV):
    service = Depends(Invalidations)
    model = Depends(Invalidation)

Args and Kwargs for required parameters

I am pretty sure I am either missing something or this isn't possible yet. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions