fairdm.views.mixins#
Mixins for views nested behind the detail page of a core model.
Module Contents#
Classes#
Fetch a related object from the URL and add it to the context. |
API#
- class RelatedObjectMixin#
Fetch a related object from the URL and add it to the context.
Meant for views behind the detail page of a core model, such as plugins. The object is looked up by the URL keyword named in
base_object_url_kwarg.Attributes: base_model: The model class the related object is fetched from. base_object_url_kwarg: Name of the URL keyword holding the object’s uuid.
Example: class SampleListView(RelatedObjectMixin, ListView): def get_queryset(self): return self.base_object.samples.all()
- base_model: django.db.models.Model | None#
None
- base_object_url_kwarg#
‘uuid’
Resolve the related model class from the uuid in the URL.
Returns: The model class the uuid belongs to.
- base_object()#
Fetch the related object named by the uuid in the URL.
Responds with a 404 when no such object exists.
Returns: The instance of
base_modelwith that uuid.
- get_context_data(**kwargs)#
Add the related object, its model and the model name to the context.