Django 1.8 add created_by when upload image in admin

12 views
Skip to first unread message

gerard

unread,
Feb 25, 2016, 3:05:25 PM2/25/16
to Django users
Hello all,

I'm trying to add the user when upload a file using the admin in Django.
The model is:
class Image(models.Model):
image = models.FileField(upload_to=DIR_IMAGES, max_length=500)
created_by = models.ForeignKey(User, related_name='created_by',
editable=False)

in admin.py, i have:
class ImageAdmin(admin.ModelAdmin):
def myfunc(self, obj):
return obj.created_by

fieldsets = [
(None, {'fields': ['image']}),
('', {'fields': ['myfunc', ]})
]

and i fails with message:
http://localhost:8003/admin/catalogue/image/add/
FieldError at /admin/catalogue/image/add/
Unknown field(s) myfunc specified for Image. Check
fields/fieldsets/exclude attributes of class ImageAdmin.

where am i wrong?

Thanks in advance for help

--
Gérard Henry
Reply all
Reply to author
Forward
0 new messages