Reputation: 14317
When I save objects using django model of save like this:
rank = Rank()
rank.save(using="test")
I would like to save bulk of ranks like this:
Rank.objects.bulk_create(ranks)
-
how can I send to is also the using
parameter?
Upvotes: 2
Views: 677
Reputation: 53669
You can use using()
on the queryset:
Rank.objects.using('test').bulk_create(ranks)
Upvotes: 5
Reputation: 47354
If I understood problem correctly you need to create custom model manager for that and override bulk_create method inside of it.
class CompanyManager(models.Manager):
def bulk_create(self, self, objs, batch_size=None, **kwargs):
using = kwargs.get('using')
if using:
# your code here
now in Rank model you can specify CompanyManager as default:
class Rank(models.Model):
objects = CompanyManager()
Upvotes: 2