daniyalzade / django_reverse_admin

Django Reverse Admin
BSD 3-Clause "New" or "Revised" License
199 stars 54 forks source link

Can we pass a method in inline_reverse #224

Open arycloud opened 3 years ago

arycloud commented 3 years ago

I have to choose the ForeignKey field on the base of a condition, so can we create a method to return the field after fulfilling the condition and then use that method in the inline_reverse

Here what I tried:

class ReportAdmin(ReverseModelAdmin):
    def get_report_model(self):
        model = None
        if ReportsModel.cdr_report is not None:
            model = CurrencyDistributionModel
        elif ReportsModel.cme_report is not None:
            model = CurrencyManagementExpenditureModel
        elif ReportsModel.cps_report is not None:
            model = CurrencyProcessingStorageModel
        elif ReportsModel.cma_report is not None:
            model = CurrencyManagementAssetsModel
        return model
    search_fields = ['name']
    inline_reverse = ['get_report_model']