How to set for m2m-field different querysets for each inline object?

How to set for m2m-field different querysets for each inline object?



class SomeModel(models.Model):
    my_m2m_field = models.ManyToManyField(OtherModel)

class SomeModelInlineAdminForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(MyInlineAdminForm, self).__init__(*args, **kwargs)

        self.fields['my_m2m_field'].queryset = OtherModel.objects.filter(somemodel__isnull=True)

class SomeModelInlineAdmin(admin.TabularInline):
    model = SomeModel
    form = SomeModelInlineAdminForm

Comments

Popular posts from this blog

How to build unlimited levels menu through PHP and MySQL

How to build a map of the frequency with which characters occur in a file in OCaml?

How to create timed pop-up windows using MVVM?