'Django Form: How to create a new related object to a multiple select widget
I am quite sure I am missing something obvious at this point.
Lets say I want to create a planed trainingssession which model looks like this:
class PlannedTrainingSession(models.Model):
created_by = models.ForeignKey(Member, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
aimed_date = models.DateField(null=True, blank=True)
team = models.ForeignKey(Squad, null=True, blank=True, on_delete=models.CASCADE)
run = models.ForeignKey(PlannedRun, null=True, blank=True, on_delete=models.CASCADE)
and a run which model looks like this:
class PlannedRun(models.Model):
name = models.CharField(max_length=200, blank=True, null=True)
description = models.CharField(max_length=5000)
distance = models.PositiveIntegerField(null=True, blank=True)
effort = models.CharField(max_length=8,
choices=[('low', _('low')), ('moderate', _('moderate')),
('intense', _('intense'))], blank=True)
Now I basically want to recreate the functionality of the django admin interface, where I could create a PlannedTrainingSession with a form and select or add a related PlannedRun. So basically an add button next to the selection drop down which then opens a new form in a tab.
How would I achieve that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
