[Fixed]-Uploading files using Django Admin

27👍

Nothing special to do, django-admin has it already.

models.py

class Router(models.Model):
    specifications = models.FileField(upload_to='router_specifications')

admin.py

from django.contrib import admin
from my_app import models

admin.site.register(models.Router)

You’ll see a file upload field in your model’s admin now. If already a file for the model instance, you’ll see a link to it as well.

When rendering a view to a user, pass the model(s) in the view’s context and use the field’s url property to link to the file.

<a href="{{ my_model_instance.specifications.url }}">Download PDF</a>

Leave a comment