Django and DRF
331 subscribers
98 photos
39 files
161 links
Purpose is sharing, spreading knowledge which is most related to the Django and Django Rest Framework(DRF)

You can find in here my
- Articles
- Projects with source codes
- Videos
and another useful stuffs
Download Telegram
Django da ko'p qilinadigan xatolar #1

Model save() metodida quyidagi holatni ko'p ishlatish


class User(models.Model):
def save(self, *args, **kwargs):
if not self.pk:
send_welcome_email(self.email)
super().save(*args, **kwargs)

yaxshidek ko'rinadi ammo unday emas, agar kodda kimdur bulk_create() ishlatgan holda 10k user yaratgan bo'lsa 10k email yuborlmay qoladi🫠

shuning uchun bunaqa ishlarni odatda signals da yoki user save qilayotgan joyda task orqali hal qilish yaxshi yechim 👌
🫡51
https://medium.com/@pesarakex/how-i-reduced-a-3gb-django-table-query-from-12s-to-200ms-with-just-3-indexes-eec82e99cec9

Django model:

class Record(models.Model):
user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
status = models.CharField(max_length=50)
created_at = models.DateTimeField(auto_now_add=True)

class Meta:
indexes = [
models.Index(fields=['user', 'status'], name='idx_record_user_status'),
models.Index(fields=['-created_at'], name='idx_record_created_at'),
models.Index(fields=['user', 'status', '-created_at'], name='idx_record_user_status_created'),
]
Lesson?
You don’t need 17 microservices when you can write clean Django apps with clear domain boundaries. Monoliths scale just fine if you don’t treat them like spaghetti.

Link to the article
👍1