# Can you use formsets for a table grid?

**URL:** <https://forum.djangoproject.com/t/can-you-use-formsets-for-a-table-grid/8423>\
**Category:** Using Django\
**Created:** [June 19, 2021, 10:21am UTC](https://forum.djangoproject.com/t/can-you-use-formsets-for-a-table-grid/8423 "2021-06-19T10:21:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MacMaxim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/macmaxim/32/4865_2.png) [@MacMaxim](https://forum.djangoproject.com/u/MacMaxim)\
**Post date:** [June 19, 2021, 10:21am UTC](https://forum.djangoproject.com/t/can-you-use-formsets-for-a-table-grid/8423/1 "2021-06-19T10:21:14Z")

</div>

We want to create a web page where students can give a grade for the lessons they have received.They can grade the lessons for each day of the week. So they can grade the lessons of a particular course. These lessons may have been given on any day of the week, like this:

 ![example](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/e/e033cb9956441733b16fb540accf4ddb3915b7ef.png)

The database contains the following tables:

```auto
class Course(models.Model):
	title = models.CharField(max_length=88, null=True)
	startdate = models.DateField()
	enddate = models.DateField()

```

```auto
GivenGrades
	course = models.ForeignKey(Course, on_delete=models.Cascade)
	date = models.DateField()
	grade = models.IntegerField(null=True)

```

Each cell in the grid is actually a form on itself, so we are considering using a formset construction, but how to shape it? We are faced with the problem that not all courses on each day have a grade. Also, the question with formsets is how to get the titles of courses per line on the form.

Schould we use formsets or is there a better way to get this done? And is there an example somewhere of how to achieve a grid-like formset like this?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 19, 2021, 11:20am UTC](https://forum.djangoproject.com/t/can-you-use-formsets-for-a-table-grid/8423/2 "2021-06-19T11:20:07Z")

</div>

I’m not sure I’d try to use a formset here - I guess it’s do-able, but I’m not sure the UX is what you’d be looking for.  
This is a case where I think I’d try to find a JavaScript-based grid tool - perhaps something like the jQuery Datatables module with the Editor plugin.

As far as getting the titles on each line, that’s actually pretty easy. See my comment here - [Forms fields based on database content - #3 by logikonabstractions](https://forum.djangoproject.com/t/forms-fields-based-on-database-content/8317/3), and the pages linked from it. (Briefly, there’s a formset function, get\_form\_kwargs, that supplies the index of each form as it’s being built, allowing you to customize the form based upon the instance of the form.)

---

<div class="post-metadata">

**Author:** ![MacMaxim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/macmaxim/32/4865_2.png) [@MacMaxim](https://forum.djangoproject.com/u/MacMaxim)\
**Post date:** [June 19, 2021, 7:28pm UTC](https://forum.djangoproject.com/t/can-you-use-formsets-for-a-table-grid/8423/3 "2021-06-19T19:28:24Z")

</div>

Thanks for the reply, Ken, appreciated !
