0

I have broker and broker subscription to programs as defined blow. Given the django docs, it should be no brainy work to setup program subscription as inline in broker admin view, but its not working as expected. Do I need to add form for inline also ?

# Models
class Broker(models.Model):
   ...
   program_subscriptions = models.ManyToManyField(Program, through='ProgramSubscriptions')


class ProgramSubscriptions(models.Model):
    broker = models.ForeignKey(Broker, on_delete=models.CASCADE)
    program = models.ForeignKey(Program, on_delete=models.CASCADE)

#Admin
class BrokerForm(forms.ModelForm):
    class Meta:
        model = Broker
        fields = ('__all__')

class ProgramSubscriptionsInline(admin.TabularInline):
   model = ProgramSubscriptions
   extra = 0

class BrokerAdmin(admin.ModelAdmin):
    model = Broker
    form = BrokerForm
    inlines = (ProgramSubscriptionsInline,)
    exclude = ('program_subscriptions',)

admin.site.register(Broker, BrokerAdmin)

Edits:

I dont see anything for program subscription in broker edit view. What I expected was dropdown for each program at-least and list of all program to which broker is subscribed etc ..

sakhunzai
  • 13,900
  • 23
  • 98
  • 159
  • Could it be because of `exclude = ('program_subscriptions',)`? – Cyrlop Mar 25 '19 at 11:43
  • Since you're not doing anything fancy with `BrokerForm` I would remove it and not specify any form in `BrokerAdmin`, maybe it's overwriting the inline? – Cyrlop Mar 25 '19 at 11:44

0 Answers0