0

I have been trying this for the past day but still can't work on it.

Consider that the user uploads a ReportCard with

models.py

class ReportCard(models.Model):
  student_id = models.CharField(max_length=15)
  report_card = models.CharField(max_length=20)

I use CharField since it could be dynamic and so I store it this way.

So in my

views.py

  if report_card_form.is_valid():
    student_id = report_card_form.cleaned_data['id']
    report_card = request.FILES['report_card']
    report_card_form.save(student_id, report_card)

and of course, in my

forms.py

def save(student_id, report_card):
  count_report = ReportCard.objects.filter(student_id=student_id).count() + 1
  new_name = student_id + '_' + str(count_report+1)
  rc = ReportCard(student_id=student_id, report_card=new_name)

Each report card is saved in the folder that belongs to each student. Every student has his/her own folder.

My question is, how do I rename the report card file, and save it in the correct folder? I am not using models but I still think there is a possible way. Tried using os to rename the files but still to no avail. Any takers?

bryan.blackbee
  • 1,934
  • 4
  • 32
  • 46

0 Answers0