Destin super service
Download 0.91 Mb.
|
Hisobot
from rest_framework.authtoken.models import Token
@receiver(post_save, sender=settings.AUTH_USER_MODEL) def create_auth_token(sender, instance=None, created=False, **kwargs): if created: print("kirdi") Token.objects.create(user=instance) return redirect("/api-token-auth/") Aynan shu modellar uchun API chiqardik. Blog Site Keyingi haftada esa Blog Site qildik, quyida uning modelini ko’rishingiz mumkin: from django.db import models from helpers.models import BaseModel # Create your models here. class FAQ(BaseModel): title = models.CharField(max_length=256) content = models.TextField() from django.db import models from helpers.models import BaseModel from author.models import Author # Create your models here. CREATED = "created" MODERATION = "moderation" PUBLISHED = "published" POST_STATUS = ( (CREATED, "created"), (MODERATION, "moderation"), (PUBLISHED, "published"), ) class Category(BaseModel): title = models.CharField(max_length=128) slug = models.CharField(max_length=128, unique=True) icon = models.FileField(upload_to="category/") post_count = models.IntegerField(default=0) class Tag(BaseModel): title = models.CharField(max_length=128) slug = models.CharField(max_length=128, unique=True) class Post(BaseModel): title = models.CharField(max_length=128, verbose_name='Nomi') slug = models.CharField(max_length=128, unique=True) content = models.TextField() sub_content = models.CharField(max_length=128) image = models.ImageField(upload_to="post/", null=True) author = models.ForeignKey( Author, on_delete=models.CASCADE, related_name='posts') category = models.ForeignKey( Category, on_delete=models.SET_NULL, null=True, related_name='posts') tags = models.ManyToManyField(Tag, related_name='posts') published_date = models.DateField(null=True) status = models.CharField(max_length=15, choices=POST_STATUS) read_min = models.IntegerField(default=0) views_count = models.PositiveIntegerField(default=0) is_popular = models.BooleanField(default=False) Ushbu model uchun API chiqardik. Xulosa Amaliyot o’ylaganimdan ham ko’ra muvafaqqiyatli bo’ldi. Ko’p bilmagan narsalarimni o’rgandim, bilganlarimni esa yana ham yaxhiroq tushunib oldim. Hammasidan ham qiziq bo’lgani bu albatta telegram botlar, uning qiziq tarafi shundaki, muammoga yechim topish uchun imkoniyat kam, lekin shu imkoniyatlardan turib yechim topa olasiz. Oddiy misol tariqasida aytsam, web ilovaarda pagination degan tushuncha bor, ya’ni aytayli productlar soni ko’p bo’lsa uni hammasini bitta sahifada emas bir nechta sahifada chiqarish. Ayni shu vazifani telegram botda qilish uchun o’zingiz qo’lda pagination uchun kod yozasiz, bor imkoniyatdan foydalanib dizayn qilasiz, interface qulayligini ham ta’minlashingiz kerak. Bu esa juda qiziq. Boshqa qilgan ishlarim qiziq emas deb ayta olmayman, qolgan ishlarning ajoyibligi iki uch qator kod orqali juda katta ishlar qilsangiz bo’ladi, bu albatta djangoning imkoniyatlari. Avvalasiga tushunmaysiz, nima qanday qanaqasiga bo’lganligini lekin biroz muddatdan so’ng Django frameworkini sevib qolasiz. Xulosa o’rnida shuni aytishim mumkinki, amaliyot juda manfaatli bo’ldi, juda ham ko’p yangi narsalarni o’rgandim. Download 0.91 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2025
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling