I want to make a Notes Platform where teachers can upload Notes and others can access it . The problem is whenever I am uploading the image it is going to the same folder and I am not able to categorise it according to year,branch,subject, and unit-wise. Since all the media files are uploaded to the same folder I am unable to get the logic how will i able to fetch the media/image/doc file when a user query for the notes. my model form is :-
class Note(models.Model):
  year_choices = (
        ( 1  , 'First' ),
        ( 2  , 'Second'),
        ( 3  , 'Third' ),
        ( 4  , 'Fourth')
  )
  branch_choices = (
        ( 'IT','IT'  ),
        ( 'EE','EE'  ),
        ( 'CSE','CSE'),
        ( 'EC','EC'  ),
        ( 'ME','ME'  ),
        ( 'CE','CE'  ),
  )
  unit_choices = ((1,'1'),(2,'2'),(3,'3'),(4,'4'),(5,'5'),
                 (6,'6'),(7,'7'),(8,'8'),(9,'9'),(10,'10'))
  branch = models.CharField(max_length=55,choices=branch_choices)
  year = models.IntegerField(choices = year_choices)
  subject_name = models.CharField(max_length = 15)
  unit = models.IntegerField(choices=unit_choices)
  location = 'images'
  picture = models.ImageField(upload_to = location)
My notes uploading form and searchform(for searching) is field is :-
class notesform(forms.ModelForm):
    class Meta:
        model = Note
        fields = [ 'year','branch','subject_name','unit','picture' ]
class searchform(forms.ModelForm):
    class Meta:
        model = Note
        fields = [ 'year','branch','subject_name','unit' ]
My notes adding function logic is :-
def addNotes(request):
    if request.user.is_authenticated():
        if request.method == "POST":
            form = notesform(request.POST,request.FILES)
            if form.is_valid():
                profile = Note()               
                profile.year = form.cleaned_data["year"]
                profile.branch = form.cleaned_data["branch"]
                profile.subject_name = form.cleaned_data["subject_name"]
                profile.picture = form.cleaned_data["picture"]
                post = form.save(commit=False)
                post.save()
                return redirect('Notes', pk=post.pk)
        else:
            form = notesform()
        return render(request, 'newNotes.html', {'form': form})
    else:
        return redirect('/accounts/login/')
I want to make upload in such a way that when the teacher fill the form and send upload the media the files upload according to the fields data he will be filling in. For ex:- Teacher fill the form as "First year" then "CSE branch" then "Data Structure" ad "Unit 1" , then it goes to the dynamic media folder "media/images/1/CSE/DATA_STRUCTURE/UNIT_1/".So that i can easily implement the search query .
If it can not applied in this way please suggest some other ways.
 
    