我只想获取带有文件的歌曲
这包括歌曲模型
song_genre = (
(1,"Jazz"),
(2,"Pop "),
(3,"Rock"),
(4,"Hip Hop / Rap"),
(5,"R&B / Soul"),
)
class Songs(models.Model):
name = models.CharField(max_length=1000,blank=True, null= True)
genre = models.CharField(choices=song_genre)
file = models.FileField()
def __str__(self):
return str(self.name)
我尝试使用file__isnull过滤器,但模板为空,但示例数据中包含没有歌曲的文件(歌曲文件)
from .models import Song
def song_with_file(request):
songs = Song.objects.filter(file__isnull=True)
return request(render, 'song_with_file.html', {'songs':songs})
{% include 'base.html' %}
{% block content %}
{% for song in songs%}
{{song}}
{% endfor %}
{% endblock %}