Support extra REST-paths on model
Krolken opened this issue · comments
If we take the Account model for example, as of now we assume it to be /accounts for all accounts and /account/number to get a specific account.
But the model in visma needs a fiscal year as of /accounts/fiscal_year/number.
There are a number of other special cases like this in the api specification so it would be beneficial to have a generic way of handling these cases.
First we need to add constraints on the endpoints that needs extra information.
So we will get an error if doing Account.objects.get(number)
Example case would be to be create the manager to need the fiscal year on get, ex: Account.objects.get(pk=number, fiscal_year=fiscal_year)
But this might get tricky since Accounts also supports the accounts/standardaccounts and accounts/fiscal_year
So maybe better to add it in the query. Like Account.objects.all().with('standradaccounts') and Account.objects.all().with(fiscal_year=fiscal_year_object)
It would then also be able to add more paths with new with statements. But order would be held intact. Also it could support taking non primary key values from objects to use in the path.
Like: Account.objects.all().with('fiscal_year__name'=fiscal_year)