IMGIITRoorkee / omniport-backend

The Django backend of the one true portal for any and every educational institute
GNU General Public License v3.0
68 stars 22 forks source link

Make the widget attached to the contenttype fields generic #155

Open algomaster99 opened 3 years ago

algomaster99 commented 3 years ago

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. https://github.com/IMGIITRoorkee/omniport-backend-formula-one/pull/3
  2. https://github.com/IMGIITRoorkee/omniport-backend-formula-one/pull/5
  3. https://github.com/IMGIITRoorkee/omniport-backend/pull/81

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

algomaster99 commented 3 years ago

@pradumangoyal told me about an existing package which does this. However, while skimming through the codebase, I could not find functionality for pagination or search. But I may be wrong and in that case, feel free to close the ticket.