diff options
Diffstat (limited to 'archaeological_operations')
| -rw-r--r-- | archaeological_operations/models.py | 10 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 17 |
2 files changed, 26 insertions, 1 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 70c1c02ba..cf648a43a 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -38,7 +38,7 @@ from ishtar_common.models import GeneralType, BaseHistorizedItem, \ SourceType, Person, Organization, Town, Dashboard, IshtarUser, ValueGetter,\ DocumentTemplate, ShortMenuItem, DashboardFormItem, GeneralRelationType,\ GeneralRecordRelations, post_delete_record_relation, OperationType, \ - ImageModel, post_save_cache + ImageModel, post_save_cache, PersonType class RemainType(GeneralType): @@ -252,6 +252,14 @@ class Operation(ClosedItem, BaseHistorizedItem, ImageModel, OwnPerms, "common_name", "comment", "address", "old_code"] INT_SEARCH_VECTORS = ["year"] M2M_SEARCH_VECTORS = ["towns__name"] + ASSOCIATED = { + "scientist": { + ('person_types', PersonType): ( + 'head_scientist', + 'sra_agent' + ) + }, + } # fields definition creation_date = models.DateField(_(u"Creation date"), diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index b75c02cae..ec7ae44c5 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -857,6 +857,23 @@ class OperationTest(TestCase, OperationInitTest): parcel.save() self.assertEqual(parcel.external_id, 'blabla') + def test_associated(self): + scientist = Person.objects.create(name="C-3PO") + self.item.scientist = scientist + self.item.save() + scientist = Person.objects.get(pk=scientist.pk) + self.assertIn(PersonType.objects.get(txt_idx='head_scientist'), + scientist.person_types.all()) + + # do not change if in the list + sra = Person.objects.create(name="R2D2") + sra.person_types.add(PersonType.objects.get(txt_idx='sra_agent')) + self.item.scientist = sra + self.item.save() + self.assertNotIn(PersonType.objects.get(txt_idx='head_scientist'), + sra.person_types.all()) + + def create_relations(self): rel1 = models.RelationType.objects.create( symmetrical=True, label='Include', txt_idx='include') |
