Skip to content

Make the widget attached to the contenttype fields generic #155

@algomaster99

Description

@algomaster99

Is your feature request related to a problem? Please describe.
A long standing issue in Django had a direct consequence on our project. Contenttype fields, entity_content_type and entity_object_id, (default names suggested by the Django framework) did not have a good widget attached to them so one had to manually query the database to find the instance ID in order to populate the fields.

In 2019, a PR was submitted and merged which added a workaround to select entity_content_type using a dropdown list and the entity_object_id from a popup window. Being a workaround, it also brought some limitations with it.

  1. Under-the-hood JavaScript written to render the popup window only gets triggered when the fields are named entity_content_type and entity_object_id. This posed problems in apps like noticeboard where the field names are different - persona_content_type.
  2. The code is not reusable which undermines the philosophy of Omniport.

Describe the solution you'd like
To convert this workaround into a concrete solution, I suggest making a Django Widget or a model field in a different repository (let's keep it under @IMGIITRoorkee only). Further, we can publish the package to PyPI. Eventually, solving both of the problems listed above.

The widget or the model field should add the following functionality:

  1. Convert the entity_content_type (the name can by anything) field from a text field to dropdown list.
  2. Clicking an option in the list should trigger a pop-up which would contain all instances of the selected model in contenttype.
  3. The instances in the pop-up window should be paginated so that the request doesn't timeout.
  4. It should also have a search functionality so that the maintainers do not spend too much time finding the instance they are looking for.
  5. Support for adding custom styles to the widget. Not a priority at all.
  6. Upon clicking an instance, the pop-up should close and write its primary key to the entity_object_id (again, name can be anything) field.

There can be more features or the implementation might be different but that is subjected to the discussion under this ticket.

Additional context
PRs related to the previous work on this.

  1. [WIP] Enable selection of contenttype object omniport-backend-formula-one#3
  2. Trigger a popup when a ContentType is selected omniport-backend-formula-one#5
  3. Trigger function to populate contenttype objects in concerned forms #81

Want to take up?
Definitely up for reviewing or answering more questions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    challengeShould pose considerable difficulty

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions