ensure same class
This commit is contained in:
parent
14e94a0c7d
commit
65f2ae7dac
@ -1,5 +1,8 @@
|
||||
|
||||
def merge(from_obj, to_obj):
|
||||
if not isinstance(from_obj, type(to_obj)):
|
||||
raise ValueError("both objects must be of the same type")
|
||||
|
||||
for related in from_obj._meta.get_all_related_objects():
|
||||
accessor_name = related.get_accessor_name()
|
||||
varname = related.field.name
|
||||
|
@ -8,6 +8,10 @@ class MergeTests(TestCase):
|
||||
self.b = Person.objects.create(name='bee')
|
||||
self.g = Group.objects.create(name='Team Awesome')
|
||||
|
||||
def test_same_class(self):
|
||||
with self.assertRaises(ValueError):
|
||||
merge(self.a, self.g)
|
||||
|
||||
def test_fk_simple(self):
|
||||
Number.objects.create(person=self.a, number='555-1111')
|
||||
Number.objects.create(person=self.a, number='555-1112')
|
||||
|
Loading…
Reference in New Issue
Block a user