B
B
bbquite2021-11-15 12:02:56
Python
bbquite, 2021-11-15 12:02:56

How to properly send django notifications?

There is the following category model:

class Category(MPTTModel, models.Model):
    is_active = models.BooleanField(
        verbose_name='Активно', default=True)
    parent = TreeForeignKey(
        'self', verbose_name='Родительская категория', related_name='childs',
        on_delete=models.CASCADE, blank=True, null=True)
    title = models.CharField(
        verbose_name='Название', max_length=1024)
    slug = models.SlugField(
        verbose_name='Слаг', max_length=1024)

    def save(self, *args, **kwargs):

        if self._state.adding:
            >>> CODE

        super(Category, self).save(*args, **kwargs)

About adding a new category, you need to send notifications to the personal account of users. If there are a couple of users, this is not a problem, but if there are 10k or more, then each time you add a new category (for example, from the admin panel), you will need to wait 5 minutes until notification objects are created, etc.
How can this system be properly implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Nesterov, 2021-11-15
@AlexNest

Use asynchronous tasks.
For example, using celery.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question