Destin super service
Download 0.91 Mb.
|
Hisobot
Social Media
Ikkinchi haftada esa Social Media APP ga API chiqardik. Quyida Social Media ning modeli bilan tanishib chiqishingiz mumkin: from django.db import models PUBLIC = "Public" ONLY_ME = "Only_me" FRIENDS = "Friends" POST_TYPE = ( (PUBLIC, "Public"), (ONLY_ME, "Only_me"), (FRIENDS, "Friends"), ) class Post(models.Model): user = models.ForeignKey("common.User", on_delete=models.CASCADE) image = models.ImageField(upload_to = "post_images/") file = models.FileField(upload_to = "post_files/") content = models.TextField() shares_count = models.PositiveIntegerField(default=0) type = models.CharField(max_length=64, choices=POST_TYPE) visible_for_users = models.ManyToManyField("common.User", related_name="visible_profiles", blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Comment(models.Model): post = models.ForeignKey(Post, on_delete=models.CASCADE) from_user = models.ForeignKey("common.User", on_delete=models.CASCADE) message = models.TextField() from django.db import models from common.models import User from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from post.models import Post COMMENT = "Comment" FOLLOW = "Follow" LIKE = "Like" SHARE = "Share" ADD = "Add" NOTIFICATION_CHOICES = ( (COMMENT, "Comment"), (FOLLOW, "Follow"), (LIKE, "Like"), (SHARE, "Share"), (ADD, "Add"), ) class Notification(models.Model): to_user = models.ForeignKey(User, on_delete=models.CASCADE) type = models.CharField(max_length=64, choices=NOTIFICATION_CHOICES) text = models.TextField() content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') is_read = models.BooleanField(default=False) from tkinter import ON from django.db import models from common.models import User HALF_HOUR = "30 minutes" ONE_HOUR = "1 soat" TEN_HOUR = "10 soat" ONE_DAY = "24 soat" USER_CHOICE = "Xohlaganimda yoqaman" MUTE_CHOICES = ( (HALF_HOUR, "30 minutes"), (ONE_HOUR, "1 soat"), (TEN_HOUR, "10 soat"), (ONE_DAY, "24 soat"), (USER_CHOICE, "Xohlaganimda yoqaman"), ) class Chat(models.Model): owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name="chat_owner") members = models.ManyToManyField(User) mute_for = models.CharField(max_length=64, choices=MUTE_CHOICES) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) active_at = models.DateTimeField(auto_now=True) def create_message(self,content): message = Message.objects.create(chat=self,content = content) return message class Message(models.Model): user = models.ForeignKey(User,on_delete=models.CASCADE) chat = models.ForeignKey(Chat, on_delete=models.CASCADE) content = models.TextField(max_length=4096) is_read = models.BooleanField(default=False) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) 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