0

I am writing a django application, that stores and displays working hours of employees.

The problem is, that for example pediatrists have 2 types of working hours - separate for sick children and healthy ones.

So I thought, it would be cool, to use HTML table to display the hours for each employee. My idea was to have a "ListField" representing each row of table, with ForeignKey to employee. That way, admin could create lists like:

['', 'Sick Children', 'Healthy Children'],
['Monday', '8-12', '12-14'],
['Friday', '12-15']

And it would appear on website, as an HTML table, that would look pretty nice.

The thing is, I would love it to look easy and intuitive for an admin of website. So I would love to keep the table rows as inline of employee in admin panel. So, I have created models:

class TableRow(models.Model):
    employee = models.ForeignKey(Employee)

class TableCell(models.Model):
    content = models.CharField(max_length=20)
    row = models.ForeignKey(TableRow)

And tried stuff like:

class TableCellInline(admin.TabularInline):
    model = TableCell

class TableRowInline(admin.TabularInline):
    model = TableRow

class EmployeeAdmin(admin.ModelAdmin):
    inlines = [TableRowInline]

admin.site.register(Employee, EmployeeAdmin)
admin.site.register(TableRow, TableRowAdmin)

Which doesn't work (as I expected, but didn't hurt to try). Admin panel shows an option to add table row, when adding/editing employee, but doesn't show any option to add any cell to the row.

Is there any way to allow adding the rows while editing/adding employee? Or maybe a totally different way to solve the problem?

mpiekarz
  • 271
  • 4
  • 15

1 Answers1

0

What you're trying to do is commonly referred to as nested inlines. Unfortunately, I'm afraid this is still not supported by the admin. See the following resources for more information.

Nested inlines in the Django admin?

#9025 assigned New feature: Nested Inline Support in Admin

Community
  • 1
  • 1
koniiiik
  • 4,240
  • 1
  • 23
  • 28