I have a class :
class Foo(models.Model):
file = models.FileField(upload_to = "/tmp/")开发者_JAVA百科
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
You could define a custom method to return the line, then display it as a readonly field:
class FooAdmin(admin.ModelAdmin):
readonly_fields = ('display_file',)
def display_file(self, obj):
line = f.readlines()[0]
return line
精彩评论