【发布时间】:2021-02-22 04:40:10
【问题描述】:
我想计算一个艺术家制作的视频数量,请告诉我哪里错了?
这是我在 admin.py 文件中的代码
class ArtistAdmin(admin.ModelAdmin):
list_display = ['name', 'date_of_birth', 'artist_videos']
def artist_videos(self, obj):
count = 0
for artistcount in Artist.objects.all():
if artistcount.name == VideoList.artists:
count = count + 1
return count
她是我在 models.py 中的代码
class Artist(models.Model):
name = models.CharField(max_length=200)
date_of_birth = models.DateTimeField()
def __str__(self):
return self.name
class VideoList(models.Model):
title = models.CharField(max_length=200)
artists = models.ManyToManyField(Artist)
def __str__(self):
return self.title
【问题讨论】: