I'm tearing hair out here trying to do something that feels like it should be simple, but I can't work out how to do this in Django.
I have three models.
class Survey()
name = models.CharField(max_length=100)
class Reference()
field = models.ForeignKey(Survey)
class SurveyItem()
field = models.ForeignKey(Survey)
reference = models.ForeignKey(Reference, blank=True, null=True)
I want to be able to show these on a single form, so when a user has created a survey and added some references for their survey, they are then able to choose add SurveyItems with that Reference in the inline part of the form.
class SurveyInfoItemInline(admin.TabularInline):
model = SurveyInfoItem
extra = 3
class ReferenceItemInline(admin.TabularInline):
model = Reference
extra = 2
class StaticSurveyAdmin(admin.ModelAdmin):
inlines = [ReferenceItemInline, SurveyItemInline]
I currently have this form created, and it's clunky, but people can make submissions successfully with it.
However, but I can't see a way to scope an inline form, so that when users are creating SurveyInfoItems on a Survey with the SurveyInfoItemInline widget, they only choose from References that were added previously to this survey, rather than showing all the References in the table on an app.
I've looked through stackoverflow, and found a few similar questions:
- Django Admin filtering ForeignKey dropdown based on another field
- Limit the queryset of entries displayed for a django admin Inline
But pretty much everything I've tried has failed to affect how many References are available to choose from.