django_unicorn.typer
#
Module Contents#
- django_unicorn.typer.get_args(type_hint)#
- django_unicorn.typer.type_hints_cache#
- django_unicorn.typer.function_signature_cache#
- django_unicorn.typer.CASTERS#
- django_unicorn.typer.get_type_hints(obj) Dict #
Get type hints from an object. These get cached in a local memory cache for quicker look-up later.
- Returns:
An empty dictionary if no type hints can be retrieved.
- django_unicorn.typer.cast_value(type_hint, value)#
Try to cast the value based on the type hint and django_unicorn.call_method_parser.CASTERS.
Additional features: - convert int/float epoch to datetime or date - instantiate the type_hint class with passed-in value
- django_unicorn.typer.cast_attribute_value(obj, name, value)#
Try to cast the value of an object’s attribute based on the type hint.
- django_unicorn.typer.get_method_arguments(func) List[str] #
Gets the arguments for a method.
- Returns:
A list of strings, one for each argument.
- django_unicorn.typer.is_queryset(obj, type_hint, value)#
Determines whether an obj is a QuerySet or not based on the current instance of the component or the type hint.
- django_unicorn.typer.create_queryset(obj, type_hint, value) django.db.models.QuerySet #
Create a queryset based on the value. If needed, the queryset will be created based on the QuerySetType.
For example, all of these ways fields are equivalent:
- class TestComponent(UnicornView):
queryset_with_empty_list: QuerySetType[SomeModel] = [] queryset_with_none: QuerySetType[SomeModel] = None queryset_with_empty_queryset: QuerySetType[SomeModel] = SomeModel.objects.none() queryset_with_no_typehint = SomeModel.objects.none()
- Params:
obj: Object. type_hint: The optional type hint for the field. value: JSON.