Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
scheung38 opened this issue Oct 28, 2022 · 0 comments
Open

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

scheung38 opened this issue Oct 28, 2022 · 0 comments

Comments

@scheung38
Copy link

scheung38 commented Oct 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant