Skip to content

<ul class="errorlist"><li>This field is required.</li></ul> #75

@scheung38

Description

@scheung38

This is my code and Excel sample:

Screenshot 2022-10-28 at 22 39 54

model.py


class Address(models.Model):
    BOOL_CHOICES = (('TRUE', True), ('FALSE', False))
    
    _id = models.ObjectIdField()
   
    Details_to_look_for = models.CharField(max_length=7, blank=True, help_text="Details_to_look_for")

    Key_Words = models.CharField(max_length=38, blank=True, help_text="Key_Words")

    Address = models.BooleanField(choices=BOOL_CHOICES, default='TRUE')
    
    Rule = models.CharField(max_length=14, blank=True, help_text="Rule")

    Name_1 = models.CharField(max_length=55, blank=True, help_text="Name_1")
    Address_1 = models.CharField(max_length=35, blank=True, help_text="Address_1")
    Address_2 = models.CharField(max_length=35, blank=True, help_text="Address_2")
    Address_3 = models.CharField(max_length=35, blank=True, help_text="Address_3")
    Address_4 = models.CharField(max_length=35, blank=True, help_text="Address_4")
    Address_5 = models.CharField(max_length=35, blank=True, help_text="Address_5")

view.py

from rest_framework.decorators import api_view
from django import forms
from django_excel import ExcelMixin
from paf.models import (
    Address,
)

import django_excel as excel


   try:

        if request.method == 'POST':
            form = UploadFileForm(request.POST, request.FILES)
            print("form: {}".format(form))

 
            if form.is_valid():
                filehandle = request.FILES['address.xlsx']
                excel.ExcelMixin.save_book_to_database(
                    models=[Address],
                    initializers=[None],
                    mapdicts=[
                        ['Key_Words', 'Name_1', 'Address_1', 'Address_2', 'Address_3', 'Address_4', 'Address_5',
                         'Address']
                    ],
                )

But error is saying?

form: <tr>
  <th><label for="id_file">File:</label></th>
 <td>
      <ul class="errorlist"><li>This field is required.</li></ul>
 <input type="file" name="file" required id="id_file">
    
 </td>

Is it related to some of the Excel cells being blank? The BooleanField maps to columns in Excel where it is either TRUE or empty cells FYI.

Doc says updated to use ExcelMixin but cannot find examples of how to upload a xlsx file and use this

excel.ExcelMixin.save_book_to_database

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions