我有一个看起来像这样的模型,为方便起见,我在这里添加了整个模型。py-
def randomizer(instance, filename):
basefilename, file_extension= os.path.splitext(filename)
chars= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'
randomstr= ''.join((random.choice(chars)) for x in range(10))
basefilename = basefilename[:10]
return '{basename}_{randomstring}{ext}'.format(basename= basefilename, randomstring= randomstr, ext= file_extension)
class Document(models.Model):
uploaded_at = models.DateTimeField(auto_now_add=True)
upload = models.FileField(upload_to=randomizer, null=True)
我想通过文件名创建搜索表单并创建对应的视图。我环顾四周,但找不到通过文件字段名称进行查询的令人信服的方法。任何帮助将不胜感激。