Omadbek Qosimov's blog
27 subscribers
43 photos
13 videos
5 files
47 links
Download Telegram
class DescriptionVariationModelInline(admin.TabularInline):
model= models.DescriptionVariationModel
extra = 22
max_num = 22
line_numbering = 0
fields = ['line_number','context']
readonly_fields = ('line_number',)

def line_number(self, obj):
self.line_numbering += 1
return self.line_numbering
๐Ÿ”ฅ8
SWAGGER_SETTINGS = {
'USE_SESSION_AUTH': False, # Admin login orqali emas, token orqali ishlatsin
'SECURITY_DEFINITIONS': {
'Bearer': {
'type': 'apiKey',
'name': 'Authorization',
'in': 'header',
'description': 'JWT formatida token kiriting: Bearer <token>'
}
},
'DEFAULT_MODEL_RENDERING': 'example',
"PERSIST_AUTH": True, # ๐Ÿ’ก Tokenni saqlab qoladi
}


#swagger #localstorage
๐Ÿ‘5
๐Ÿ‘2๐Ÿ”ฅ2
#signals
@receiver(pre_save, sender=Blogger)
def prepare_blogger_chat(sender, instance, **kwargs):
"""
Blogger saqlashdan oldin signal.
Agar blogger.user.user_type == 'blogger' bo'lsa,
uning chatini topib, undagi barcha qatnashchilarni o'chirib,
faqat bloggerning o'zini qo'shadi.
"""
# Yangi yaratilayotgan Blogger uchun hali id bo'lmaydi
if instance.id is None:
# Yangi blogger, hali chati yo'q
return

if instance.user and instance.user.user_type == 'blogger':
try:
# Blogerning chatini topamiz
# Ehtimol bo'lgan hamma chatlarini olamiz
blogger_chat = Chat.objects.filter(participants=instance.user).first()
if blogger_chat:
blogger_chat.participants.clear()
blogger_chat.participants.add(instance.user)
blogger_chat.save()
except Exception as e:
print(f"Chat qayta sozlashda xatolik yuz berdi: {e}")


@receiver(post_save, sender=Blogger)
def update_blogger_chat(sender, instance, created, **kwargs):
"""
Blogger saqlagandan keyin signal.
Agar user.user_type == 'blogger' va saler.user_type == 'sales' bo'lsa,
bloggerning chatini topib, unga salerni qo'shadi.
"""
# Faqat blogerga tegishli user va saler mavjud bo'lsa
if instance.user and instance.user.user_type == 'blogger' and instance.saler and instance.saler.user_type == 'sales':
try:
with transaction.atomic():
blogger_chats = Chat.objects.filter(participants=instance.user)

if not blogger_chats.exists():
chat = Chat.objects.create()
chat.participants.add(instance.user)
else:
chat = blogger_chats.first()
chat.participants.add(instance.saler)
chat.save()
except Exception as e:
print(f"Bloggerning chatini yangilashda xatolik yuz berdi: {e}")

elif instance.user and instance.user.user_type == 'manager' and instance.saler and instance.saler.user_type == 'sales':
try:
with transaction.atomic():
bloggers = Blogger.objects.filter(manager=instance.user)
for blogger in bloggers:
blogger.saler = instance.saler
blogger.save() # Bu o'z navbatida ushbu signal uchun yangi chaqiruvlarni yaratadi

except Exception as e:
print(f"Bloggerning chatini yangilashda xatolik yuz berdi: {e}")
โค2๐Ÿ”ฅ1
use local postgres in docker


version: "3.8"

services:
python-app:
build: .
container_name: python_app
ports:
- "8081:8000"
volumes:
- .:/app
working_dir: /app
environment:
- DB_HOST=host.docker.internal
- DB_PORT=5432
- DB_NAME=testdb
- DB_USER=postgres
- DB_PASSWORD=password
extra_hosts:
- "host.docker.internal:host-gateway"
command: python app.py
networks:
- app-network

networks:
app-network:
driver: bridge


#docker #postgres
๐Ÿ”ฅ1
"Nafs yoสปliga kirgan kishi rasvo boสปlur
Yo'ludin ozib, toyib, to'zib, gumroh bo'lur.."


Xo'ja Ahmad Yassaviy
๐Ÿ”ฅ2
"Biz nimani qayta qayta
qilayotgan boสปlsak,
demak o'shamiz"


Abu Nasr Farobiy
๐Ÿ”ฅ2
Yo yaxshi boสปladi yoki yaxshilikka.
๐Ÿ”ฅ1