About My Project -- Formset Improvement

About My Project

I worked on the “Form” layer of Django, specifically on FormSet, ModelFormSet, and InlineFormSet. This project aims to improve the above classes, add new features to them, thus enhancing their functionality and ease of use.

Django currently has a formset class which is used as a collection instance for the forms. It’s a layer of abstraction which makes it easier to work with multiple forms. Similarly, ModelFormSet and InlineFormSet are used to handle models and related models respectively.

Problem Statement of my project provided by Django

You can check the Django GSoC 2019 page here

One of the big problems in web programming is making a request object available everywhere that it might be needed. Some frameworks tackle this problem by using a thread-local. A thread-local is essentially a global variable that allows you to access stateful information, such as the currently active request.

Django takes a more structured approach and encourages you to use function arguments and class attributes to pass around stateful information. This requires more discipline on the developer but ultimately leads to a more robust, less error-prone code that is easier to test.

The counterargument to Django’s approach is that passing the request around everywhere that it might be needed is difficult. Formsets are one example given in support of this - Django’s formsets are a classic example where you might want to pass a request down to an internal form - but this is surprisingly difficult to do with Django’s FormSet infrastructure.

The problem isn’t just about requests, either - there’s a general problem in Django’s FormSet and ModelFormSet objects that makes it difficult to pass in arguments to the Forms that are on them, or otherwise control the save process. This could be a request, the user that is making a particular change, or some other “ownership” related information.

The solution I proposed and overall Goal of my project

The broad goal was to have an error-free Formset and close all the tickets related to formset. The end goal of this project was to address as many issues as possible and also make the formsets more user-friendly.

I aimed to give the user more control over the individual forms in the formset, by enabling the user to pass different arguments for init() and save() methods of each form. The next goal was to enable the user to use formsets for edit only purpose, by implementing a robust framework which will disable creating of new model objects, instead of workarounds which can’t do much in case of forged POST requests. After that, the next goal was to add some new features to formset like pagination, declarative syntax of ModelFormSet & InlineFormSet.

Click here to see my whole proposal