not updating pdf file name and image in django?

the scnerio is this, I am adding eggs info in a form and render it into anotherform and data is transfering easily but i added two fields in egg form which is pdf field and image field when i uploding these two files it is uploaded successfully and shown in media folder but it is not updating the name of pdf file as well as image and i want to download this pdf file but it is not showing so i cannot see the file and download it.

my file for egg is this

class Egg(models.Model):
    eggType = models.CharField(max_length=50)
    eggSize = models.IntegerField()
    eggWeight = models.IntegerField()
    eggPrice = models.IntegerField()
    eggPdf = models.FileField(upload_to='media/documents/', null=True, blank=True)
    eggImage = models.ImageField(upload_to='media/images/', null=True, blank=True)

    class Meta:
        constraints = [
            models.UniqueConstraint(fields=['id'], name='unique_id')

    def __str__(self):
        return f"{self.eggType} - {}"

my eggindex.html template where i edit the egg info

<div class="container" style="margin-top: 20px;">
  <h2>Egg Details</h2>
  <div class="card" style="padding-left: 30px;">
    <form id="eggform" method="POST" class="post-form" action="/eggsAdd" enctype="multipart/form-data"> 
          {% csrf_token %}
          <div class="form-row">
              <div class="form-group col-md-6">
                <label class="col-sm-2 col-form-label">Egg Type:</label> 
                <div class="col-sm-4">  
                  {{ form.eggType }}  
              <div class="form-group col-md-6">
                <label class="col-sm-2 col-form-label">Egg Size:</label>  
                <div class="col-sm-4">  
                  {{ form.eggSize }}  
          <div class="form-row">
              <div class="form-group col-md-6">
                <label class="col-sm-2 col-form-label">Egg Weight:</label>
                <div class="col-sm-4">  
                  {{ form.eggWeight }}  
              <div class="form-group col-md-6">
                <label class="col-sm-2 col-form-label">Egg Price:</label>  
                <div class="col-sm-4">  
                  {{ form.eggPrice }}  
              <div class="form-group col-md-6">
                <input type="file" name="myfile"><br><br> 
              <div class="form-group col-md-6">
                <input type="file" name="myimage" class="form-control-file">
              <div class="button-group">
            <button type="submit" class="btn btn-primary">Submit</button>  

and my eggs.html template where i want to show my eggs info

{% block content %} 
<table class="table table-striped table-bordered table-sm">  
    <thead class="thead-dark">  
        <th>Egg Type</th>  
        <th>Egg Size</th>  
        <th>Egg Weight</th>  
        <th>Egg price</th>  
        <th>Egg PDF</th>
        <th>Egg Image</th>
{% for egg in eggs %}  
        <td>{{ egg.eggType }}</td>  
        <td>{{ egg.eggSize }}</td>  
        <td>{{ egg.eggWeight }}</td>  
        <td>{{ egg.eggPrice }}</td> 
        <td><a href="{{ }}">PDF</a></td>
        {% if egg.eggImage %} 
        <td><img src="{% static %}" alt="Egg Image"></td>
        {% endif %}
            <a href="/Edit/{{ }}"><span class="glyphicon glyphicon-pencil" >Edit</span></a>  
            <a href="/deleteEgg/{{ }}">Delete</a>  
{% endfor %}  
<center><a href="/eggsAdd" class="btn btn-primary">Add New Record</a></center> 
{% endblock %} 

and here is my view for eggs

def eggsAdd(request):  
    if request.method == "POST":  
        form = eggCreate(request.POST, request.FILES)  
        if form.is_valid():  
            egg = # don't save the form yet
            egg_price = eggPrice
            total_price += egg_price

            # handle the pdf file upload
            pdf_file = request.FILES.get('myfile', None)
            if pdf_file:
                fs = FileSystemStorage()
                filename =, pdf_file)
                pdf_file_path = fs.url(filename)
                egg.eggPdf = pdf_file_path
            # handle the image file upload
            image_file = request.FILES.get('myimage', None)
            if image_file:
                fs = FileSystemStorage()
                filename =, image_file)
                image_file_path = fs.url(filename)
                egg.eggImage = image_file_path

            # save the form and redirect to the eggs info page
            eggs = Egg.objects.all() 
            return redirect('/eggsInfo')   
        form = eggCreate()  
    return render(request,'html/eggindex.html',{'form':form})

How can i show pdf file name and see the file and download it and also for image?

Note: Here in the view this code egg_price = eggPrice total_price += egg_price
is for adding the egg price and showing it on this template

<div class="container">
  <div class="card">
    <p>Total Price: {{ total_price }}</p>
          <div class="form-row">
              <div class="form-group col-md-6">

Here is my file

from django import forms
from .models import Egg, filesUplod

class eggCreate(forms.ModelForm):
    class Meta:
        model = Egg
        fields = '__all__'

Also please post your form here as well.

I have mentioned the file, kindly see the question

You’re doing a degree of work that you don’t need to do.

You’re creating a model form, which means it will handle the files directly without any real handling on your part.

You don’t need to do the GET on the uploaded files. The form field will be populated by the post. You generally don’t need and don’t want to set the name of the file as it is saved in the server. You might want to save the original name - that’s fine, but it doesn’t need to be the name of the file as it exists in the media directory. What you don’t want to have happen is have person A’s file overwritten by person B uploading a file with the same file name.

In this case, egg.eggPdf is already set to the uploaded file. If you want to keep the file’s originally-uploaded name, you can reference request.FILES['myfile'].name and save it in a different field.

That means that instead of this:

You only need something like:

if egg.eggPdf:
    egg.pdf_filename = request.FILES['myfile'].name

where pdf_filename is a new field added to the model to store the original file name.

Let Django manage the file itself.

The url attribute on the field gives you the url to use to make that file available for downloading.