nginx Django的多对多字段不断地将每个示例添加到自身

cgfeq70w  于 2022-11-02  发布在  Nginx
关注(0)|答案(1)|浏览(184)

我有模型“post”和模型“profile”。我需要给帖子添加赞,所以我一开始用了“ForeignKey”,现在我有了ManyToMany关系,但我一直看到“profile”的每个可能示例都自动添加到“post”的每个示例中。为什么会发生这种情况?我在以前的项目中没有遇到过这样的问题。
models.py 以获取配置文件

from django.db import models
from django.conf import settings
from django.contrib.auth.models import User

class Profile(models.Model):
    """Fields that can be used to modify the profile page"""
    name = models.CharField(max_length=50, null=True, blank=True)
    bio = models.TextField(max_length=160, null=True, blank=True)
    profilePicture = models.ImageField(null=True, blank=True, upload_to='profiles/', default='default/default-pfp.jpg')  
    """Technical fields unaccessable for users"""
    owner = models.OneToOneField(User, on_delete=models.CASCADE, related_name='account')
    following = models.ForeignKey("self", on_delete=models.DO_NOTHING, blank=True, null=True, unique=False)

    def __str__(self):
        str=self.owner.username
        str=str + "'s profile"
        return str

model.py 为壶

from django.db import models
from django.conf import settings
from django.contrib.auth.models import User

class Post(models.Model):
    title = models.CharField(max_length=360)
    body = models.TextField()
    image = models.ImageField(null=True, blank=True)
    likes = models.ManyToManyField(User, related_name="blog_posts")
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    date = models.DateTimeField(auto_now=False, auto_now_add=True)

    def __str__(self):
        str=self.author.username
        str= self.date.strftime("%d/%m %H:%M ") + str + "'s post"
        return str

    def date_posted(self):
        str = self.date.strftime('%H:%M %d/%m/%y')
        return str

[![管理面板][1]][1] [1]:https://i.stack.imgur.com/rwgBP.png

nue99wik

nue99wik1#

所以,他们改变了视觉界面,因为我做了我的上一个项目,我不明白,😂它没有选择所有的默认,界面只是看起来像这样。我的错,感谢那些谁想知道的时间:)

相关问题