def __init__(self, expression, *to_delete):
        from django_mysql.models.fields import DynamicField

        expressions = [expression]
        for name in to_delete:
            if not hasattr(name, "resolve_expression"):
                name = Value(name)
            expressions.append(name)

        super().__init__(*expressions, output_field=DynamicField())
Exemple #2
0
    def __init__(self, expression, to_add):
        from django_mysql.models.fields import DynamicField

        expressions = [expression]
        for name, value in to_add.items():
            if not hasattr(name, "resolve_expression"):
                name = Value(name)

            if isinstance(value, dict):
                raise ValueError("ColumnAdd with nested values is not supported")
            if not hasattr(value, "resolve_expression"):
                value = Value(value)

            expressions.extend((name, value))

        super(ColumnAdd, self).__init__(*expressions, output_field=DynamicField())
Exemple #3
0
    def __init__(
        self,
        expression: ExpressionArgument,
        to_add: dict[str, ExpressionArgument | float | int | dt.date | dt.time
                     | dt.datetime],
    ) -> None:
        from django_mysql.models.fields import DynamicField

        expressions = [expression]
        for name, value in to_add.items():
            if not hasattr(name, "resolve_expression"):
                name = Value(name)

            if isinstance(value, dict):
                raise ValueError(
                    "ColumnAdd with nested values is not supported")
            if not hasattr(value, "resolve_expression"):
                value = Value(value)

            expressions.extend((name, value))

        super().__init__(*expressions, output_field=DynamicField())
Exemple #4
0
 def test_bad_import2_deconstruct(self):
     from django_mysql.models.fields.dynamic import DynamicField as DField
     field = DField()
     name, path, args, kwargs = field.deconstruct()
     assert path == 'django_mysql.models.DynamicField'
 def test_bad_import2_deconstruct(self):
     from django_mysql.models.fields.dynamic import DynamicField as DField
     field = DField()
     name, path, args, kwargs = field.deconstruct()
     assert path == 'django_mysql.models.DynamicField'