在 django 管理表单中显示文件的第一行
我有一堂课:
class Foo(models.Model):
file = models.FileField(upload_to = "/tmp/")
attribute_1 = models.IntegerField()
attribute_2 = models.IntegerField()
在管理中:
class FooAdmin(admin.ModelAdmin):
pass
admin.site.register(Foo,FooAdmin)
如何以 FooAdmin 的更改形式显示文件的前 N 行。我说的是修改特定对象的页面,而不是可以看到所有不同 foo 对象的页面。
谢谢
干杯
I have a class :
class Foo(models.Model):
file = models.FileField(upload_to = "/tmp/")
attribute_1 = models.IntegerField()
attribute_2 = models.IntegerField()
And in the admin:
class FooAdmin(admin.ModelAdmin):
pass
admin.site.register(Foo,FooAdmin)
How can i display the N first lines of the file in the change form of FooAdmin. I'm talking of the page where you modify a specific object, not the one where you can see all different foo objects.
Thanks
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以定义一个自定义方法来返回该行,然后将其显示为只读字段:
You could define a custom method to return the line, then display it as a readonly field: