gpt4 book ai didi

python - 计算用户的帖子数量 - django

转载 作者:行者123 更新时间:2023-11-28 21:36:55 24 4
gpt4 key购买 nike

<分区>

我正在尝试克隆一个社交媒体网站。如何计算特定用户的帖子总数?

模型.py

from django.db import models
from django.utils import timezone
from django.urls import reverse
from django.conf import settings
from django.utils.text import slugify
from blog.utils import unique_slug_generator
from django.contrib.auth import get_user_model
import uuid
User = get_user_model()

class Post(models.Model):
author = models.ForeignKey(User, on_delete = models.CASCADE)
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True, blank=True, default=uuid.uuid1)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
published_date = models.DateTimeField(blank=True, null=True)
likes = models.ManyToManyField(User, related_name='post_likes', blank = True)

def get_like_url(self):
return reverse("posts:like-toggle", kwargs={"slug": self.slug})

def get_api_like_url(self):
return reverse("posts:like-api-toggle", kwargs={"slug": self.slug})

def publish(self):
self.published_date = timezone.now()
self.save()

def approve_comments(self):
return self.comments.filter(approved_comment=True)

def get_absolute_url(self):
return reverse("post_detail",kwargs={'pk':self.pk})

def __str__(self):
return self.title

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com