def update_categories(data_import, cats_list): if (not data_import): return #clear out all existing categories for Data Import Categories.remove_obj(data_import) #now add the Categories if cats_list: for cat_id in cats_list.split(","): try: Categories.objects.get(id=cat_id.strip()).add_object(data_import) except (ValidationError, Categories.DoesNotExist) as e: pass
def test_remove_obj(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat", tagged=[self.loc, di]) cat.save() cat2 = Categories(name="garfield", tagged=[self.loc]) cat2.save() self.assertEqual(2, len(Categories.for_object(self.loc))) Categories.remove_obj(self.loc) self.assertEqual(0, len(Categories.for_object(self.loc))) di.delete() cat.delete() cat2.delete()