Giter VIP home page Giter VIP logo

Comments (4)

matthewhegarty avatar matthewhegarty commented on September 22, 2024 1

Great - thanks for confirming.

from django-import-export.

matthewhegarty avatar matthewhegarty commented on September 22, 2024

Are you using v4.0.3? Are you using any third party plugins?

from django-import-export.

matthewhegarty avatar matthewhegarty commented on September 22, 2024

I couldn't reproduce this in the example app by declaring the following on the Book model:

    name = models.CharField(
        verbose_name=_("Name"),
        max_length=80,
        blank=True,  # <--- I think problem is here
    )

When we have seen this before it is because there is a custom field type (i.e. from a third party app) which is being identified as a CharField or subclass, but then is not being created with the correct Widget type.

If you could reproduce in the example app, or provide a failing test case, that would be ideal.

The other thing to check is that you are declaring resources correctly in the Admin file:

# this is correct
resource_classes = [YourResource]

# this is not correct
resource_class = YourResource

In the latter case, we have seen that this can cause issues.

from django-import-export.

OttoAndrey avatar OttoAndrey commented on September 22, 2024

@matthewhegarty Sorry for late answer.

When we have seen this before it is because there is a custom field type (i.e. from a third party app) which is being identified as a CharField or subclass, but then is not being created with the correct Widget type.

You are right. Before v4 we added own CharWidget where replace None by empty strings.

Our solution:

class CharWidget(Widget):
    """Widget for converting text fields."""

    def clean(
        self,
        value: str | None,
        row: None = None,
        *args,
        **kwargs,
    ) -> str:
        """Return empty string for values which is None.

        Since CharField can only be blank, when importing, it needs to be
        convert none to an empty string.

        """
        value = super().clean(value, row, *args, **kwargs)

        return "" if value is None else value

But now as I can see it works out of the box: docstring and code

So I think we can just remove this part of code. Thank you for help!

from django-import-export.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.