Skip to content

Admin views

hypha.apply.categories.admin_views

AddChildMetaTermViewClass

AddChildMetaTermViewClass(model_admin, parent_pk)

Bases: CreateView

View class that can take an additional URL param for parent id.

Source code in hypha/apply/categories/admin_views.py
def __init__(self, model_admin, parent_pk):
    self.parent_pk = unquote(parent_pk)
    object_qs = model_admin.model._default_manager.get_queryset()
    object_qs = object_qs.filter(pk=self.parent_pk)
    self.parent_instance = get_object_or_404(object_qs)
    super().__init__(model_admin)

parent_pk class-attribute instance-attribute

parent_pk = unquote(parent_pk)

parent_instance class-attribute instance-attribute

parent_instance = get_object_or_404(object_qs)

get_page_title

get_page_title()

Generate a title that explains you are adding a child.

Source code in hypha/apply/categories/admin_views.py
def get_page_title(self):
    """Generate a title that explains you are adding a child."""
    title = super().get_page_title()
    return title + " %s %s for %s" % (
        self.model.node_child_verbose_name,
        self.opts.verbose_name,
        self.parent_instance,
    )

get_initial

get_initial()

Set the selected parent field to the parent_pk.

Source code in hypha/apply/categories/admin_views.py
def get_initial(self):
    """Set the selected parent field to the parent_pk."""
    return {"parent": self.parent_pk}