I have a Community model that contains a ForeignKey app field that, in turn, simply stores access token.

class Community(models.Model): app = models.ForeignKey("VkApp") domen = models.CharField(max_length=300) @property def api(self): if self.app: access_token = self.app.access_token else: access_token = "" return PublicApiCommands(access_token=access_token, domen=self.domen) def get_posts(self, count): return self.api.get_post_list(count) class VkApp(models.Model): access_token = models.CharField(max_length=300) 

The get_posts method refers to the api property, and returns an object of the PublicApiCommands class, which is a wrapper around the vk api: inside it, call request.get('api.vk.com/bla?bla=bla')

Now I want to make the app not ForeignKey , but ManyToManyField , so that several different access tokens can be used to manage the same Community . Moreover, different Community tokens can either completely coincide or be completely different.

Further, for all Community.objects.all() is called on the celery task, in which community.get_posts() called. How now to make so that access_token at the same time was selected from available for this community and at the same time free at the moment?

They offered to use Queue , but I still can not figure out where to perform initialization, where to do get and put .

The head explodes: for the first time, probably met with such a challenge. Maybe you need to read something to start? I will welcome any advice. Thank!

    0