def add_prune_rule(_rule): try: obj = models.dm_prune_field.objects.get(rule=_rule) except: obj = models.dm_prune_field() obj.rule = _rule obj.save() return obj.pk