Reusing generic actions to manage relations

class aristotle_mdr.contrib.generic.views.GenericAlterForeignKey(**kwargs)[source]

A view that provides a framework for altering ManyToOne relationships (Include through models from ManyToMany relationships) from one ‘base’ object to many others.

The URL pattern must pass a kwarg with the name iid that is the object from the model_base to use as the main link for the many to many relation.

  • model_base - mandatory - The model with the instance to be altered

  • model_to_add - mandatory - The model that has instances we will link to the base.

  • template_name
    • optional - The template used to display the form.
    • default - “aristotle_mdr/generic/actions/alter_foreign_key.html”
  • model_base_field - mandatory - the name of the field that goes from the model_base to the model_to_add.

  • model_to_add_field - mandatory - the name of the field on the model_to_add model that links to the model_base model.

  • form_title - Title for the form

For example: If we have a many to many relationship from DataElement`s to `Dataset`s, to alter the `DataElement`s attached to a `Dataset, Dataset is the base_model and model_to_add is DataElement.

post(request, *args, **kwargs)[source]

Handles POST requests, instantiating a form instance with the passed POST variables and then checked for validity.

class aristotle_mdr.contrib.generic.views.GenericAlterManyToManyView(**kwargs)[source]

A view that provides a framework for altering ManyToMany relationships from one ‘base’ object to many others.

The URL pattern must pass a kwarg with the name iid that is the object from the model_base to use as the main link for the many to many relation.

  • model_base - mandatory - The model with the instance to be altered

  • model_to_add - mandatory - The model that has instances we will link to the base.

  • template_name
    • optional - The template used to display the form.
    • default - “aristotle_mdr/generic/actions/alter_many_to_many.html”
  • model_base_field - mandatory - the field name that goes from the model_base to the model_to_add.

  • form_title - Title for the form

For example: If we have a many to many relationship from DataElement`s to `Dataset`s, to alter the `DataElement`s attached to a `Dataset, Dataset is the base_model and model_to_add is DataElement.

post(request, *args, **kwargs)[source]

Handles POST requests, instantiating a form instance with the passed POST variables and then checked for validity.

class aristotle_mdr.contrib.generic.views.GenericAlterOneToManyView(**kwargs)[source]

A view that provides a framework for altering ManyToOne relationships (Include through models from ManyToMany relationships) from one ‘base’ object to many others.

The URL pattern must pass a kwarg with the name iid that is the object from the model_base to use as the main link for the many to many relation.

  • model_base - mandatory - The model with the instance to be altered

  • model_to_add - mandatory - The model that has instances we will link to the base.

  • template_name
    • optional - The template used to display the form.
    • default - “aristotle_mdr/generic/actions/alter_many_to_many.html”
  • model_base_field - mandatory - the name of the field that goes from the model_base to the model_to_add.

  • model_to_add_field - mandatory - the name of the field on the model_to_add model that links to the model_base model.

  • ordering_field - optional - name of the ordering field, if entered this field is hidden and updated using a drag-and-drop library

  • form_add_another_text - optional - string used for the button to add a new row to the form - defaults to “Add another”

  • form_title - Title for the form

For example: If we have a many to many relationship from DataElement`s to `Dataset`s, to alter the `DataElement`s attached to a `Dataset, Dataset is the base_model and model_to_add is DataElement.

post(request, *args, **kwargs)[source]

Handles POST requests, instantiating a form instance with the passed POST variables and then checked for validity.