I've had a lot of difficulty designing my db but have boiled my problem down to the core issue.
Students can enroll in Packages. Packages are groups of many Modules.
When a Student enrolls in a Package I need an Extra_Data table to be automatically generated for EACH Module in the Package, linked to the Student. This will hold data unique to one Module and one Student.
class Student(models.Model):
package = models.ManyToManyField(Package, blank=True)
class Module(models.Model):
task_type = models.CharField(max_length=200)
topic = models.CharField(max_length=200)
class Package(models.Model):
individual_modules = models.ManyToManyField(Module, blank=True)
name = models.CharField(max_length=200)
How I display Packages:
{% for package in user.student.module_packages.all %}
<table>
<th>Module</th>
<th>Task Type</th>
<th>Topic</th>
#<th>Complete</th> not yet implemented
#<th>User Files</th> not yet implemented
#<th>Teachers Files</th> not yet implemented
<h3 class="account-heading">{{ package.name }}</h2>
{% for module in package.individual_modules.all %}
<tr>
<td>{{ module.id }}</td>
<td>{{ module.task_type }}</td>
<td>{{ module.topic }}</td>
#<td>{{ module.extra_data.module_complete }}</td> this is an example of
# how I would expect to be able to handle the extra_data tables contents,
# though its turning out to be a real challenge
</tr>
{% endfor %}
{% endfor %}
I have tried many things, including using a Django through relationship between Student and Module, going 'through' Extra_Data. This didn't work as it directly links Students with Modules - when a Student is given a Package in Django Admin no Extra_Data tables are created for the Modules in the Package.
-- I think this is irrelevant to my main issue, but Students can also enroll in individual Modules --
Thank you very much.