Closed andreasnuesslein closed 6 months ago
(i'm guessing this discussion here is related to that: https://github.com/pydantic/pydantic/issues/1223 and I feel like there's no easy way)
Hi @andreasnuesslein
I think you can pass exclude_defaults
/ exclude_unset
/ exclude_none=True
, depending on your requirements to the field kwargs, e.g.:
class ConfigModel(models.Model):
l18n_config = SchemaField(schema=I18NSchema, exclude_unset=True)
!! perfect, thanks so much. totally solved exactly my situation. I feared I had to define "extras.Allow" and then dynamically parse extras etc. this is way better! :)
Hi @surenkov
I have another question regarding your pydantic field :)
I'm creating a BaseModel like so:
which basically results in a:
(I initially tried it with
default=""
too)Is there a way to not have this in the database in the end:
but only the keys that were actually set, i.e. in this case:
{"en": "hello", "fr": "bonjour"}
thanks a bunch!