-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from openimis/dataloaders
feat(dataloaders): Add dataloaders for insuree & family
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from promise.dataloader import DataLoader | ||
from promise import Promise | ||
|
||
from .models import Insuree, Family | ||
|
||
|
||
class InsureeLoader(DataLoader): | ||
def batch_load_fn(self, keys): | ||
insurees = { | ||
insuree.id: insuree for insuree in Insuree.objects.filter(id__in=keys) | ||
} | ||
return Promise.resolve([insurees.get(insuree_id) for insuree_id in keys]) | ||
|
||
|
||
class FamilyLoader(DataLoader): | ||
def batch_load_fn(self, keys): | ||
families = {family.id: family for family in Family.objects.filter(id__in=keys)} | ||
return Promise.resolve([families.get(family_id) for family_id in keys]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters