|
|
|
|
|
by bb88
319 days ago
|
|
One thing that's interesting about Django I thought was that tools like celery will "pickle" orm objects, when they really should be passing the pk's of the objects. The other thing that's interesting about Django is that you can subclass queryset to do things like .dehydrate() and .rehyrdrate() which can do the translations between json-like data and orm representations. Then replace the model manager (in Django at least) with that queryset using queryset.as_manager(). If you're trying to decompose the monolith, this is a good way to start -- since it allows you an easier time to decompose and recompose the orm data. The simplest can just be: def dehydrate(self) -> List[int]:
return list(self.values_list("id", flat=True))
def rehydrate(self, *pks) -> Self:
return self.filter(id__in=pks)
|
|