Git Product home page Git Product logo

Comments (4)

bhch avatar bhch commented on May 24, 2024

I wouldn't call it a workaround. Since you've got a callable schema, it's your responsibility to handle the errors within that callable.

As the callable is your written code, I don't think the field should automatically handle the exceptions raised in it.

from django-jsonform.

johanneswilm avatar johanneswilm commented on May 24, 2024

ok, how about adding something to the documentation about it then? Then others can benefit from me having researched this once already.

from django-jsonform.

bhch avatar bhch commented on May 24, 2024

I'll update the docs. Thank you for your suggestions.

from django-jsonform.

yswtrue avatar yswtrue commented on May 24, 2024

I have to use form to make it works

class FlowerPackForm(forms.ModelForm):
    class Meta:
        model = FlowerPack
        exclude = ["is_removed"]

    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)
        instance = kwargs.get("instance", None)
        if instance and hasattr(instance, "sku"):
            self.fields["attributes"].widget.schema = instance.sku.attribute_schema

I have try to modify the model meta field but it seams have cache, so it not allways work.

class FlowerPack(BaseModel):
    sku = models.ForeignKey(Sku, models.CASCADE, related_name="packs")
    attributes = JSONField(
        schema={"type": "object", "properties": {}},
        null=True,
        blank=True,
        verbose_name="SKU 属性列表",
    )
    def __init__(self, *args: Any, **kwargs: Any) -> None:
        super().__init__(*args, **kwargs)
        if hasattr(self, "sku"):
            field = self._meta.get_field("attributes")
            field.schema = self.sku.attribute_schema

from django-jsonform.

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.