Reputation: 165242
Is it possible to render a TextField
in the Django admin, as a file upload widget and set the TextField
's content to the content of said uploaded file?
Bonus points if it's possible to have both.
Upvotes: 2
Views: 576
Reputation: 14190
A widget renders form elements. I would just use the Django Admin's save_model(). Something like this (untested):
# models.py
class Article(models.Model):
text_file = models.FileField()
# admin.py
class ArticleAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
obj.text_file = request.FILES['text_file']
obj.save()
Upvotes: 2