Exemplo n.º 1
0
def clone_field_without_related_name(field: models.Field, ) -> models.Field:
    """Creates a clone of the given field, without a related_name."""

    if isinstance(field, models.fields.related.RelatedField):

        # ugly hack to prevent "models not ready" error
        if field.swappable:
            field = copy(field)
            field.swappable = False

        _name, _path, args, kwargs = field.deconstruct()
        kwargs.pop('related_name', None)

        return type(field)(*args, **kwargs)

    else:
        return field.clone()
Exemplo n.º 2
0
def reconstruct(field: Field) -> Field:
    """ Deconstructs and Re-constructs a field """

    name, clz, args, kwargs = field.deconstruct()
    return field.__class__(*args, **kwargs)