Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.PHONY: install
install:
python3 -m pip install build twine
python3 -m pip install -e .[dev,rest]
python3 -m pip install -e .[dev,test]


.PHONY: build
Expand Down
4 changes: 3 additions & 1 deletion django_pydantic_field/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def __init__(

def __copy__(self):
_, _, args, kwargs = self.deconstruct()
return type(self)(*args, **kwargs)
copied = type(self)(*args, **kwargs)
copied.set_attributes_from_name(self.name)
return copied

def get_default(self):
value = super().get_default()
Expand Down
10 changes: 10 additions & 0 deletions tests/test_django_model_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import typing as t
from collections import abc
from copy import copy
from datetime import date

import django
Expand All @@ -12,6 +13,7 @@
from django_pydantic_field import fields

from .conftest import InnerSchema, SampleDataclass
from .sample_app.models import Building
from .test_app.models import SampleForwardRefModel, SampleModel, SampleSchema


Expand Down Expand Up @@ -313,3 +315,11 @@ def serialize_field(field: fields.PydanticSchemaField) -> str:

def reconstruct_field(field_repr: str) -> fields.PydanticSchemaField:
return eval(field_repr, globals(), sys.modules)


def test_copy_field():
copied = copy(Building.meta.field)

assert copied.name == Building.meta.field.name
assert copied.attname == Building.meta.field.attname
assert copied.concrete == Building.meta.field.concrete