Skip to content

How would you ignore a trigger within a trigger? #190

Answered by ikokollari
ikokollari asked this question in Q&A
Discussion options

You must be logged in to vote

I made it work like so:

Model TblA(models.Model):
    field_1 = models.CharField(max_length=20)
    field_2 = models.PositiveIntegerField(default=0)

    class Meta:
        triggers = [
            pgtrigger.ReadOnly(
                name='read_only_field_2',
                fields=['field_2']
            )
        ]

class TblB(models.Model):
    field_a = models.ForeignKey(TblA, on_delete=models.SET_NULL)

    class Meta:
        triggers = [
            pgtrigger.Trigger(
                func=pgtrigger.Func('''
                        BEGIN
                            SELECT CURRENT_SETTING('pgtrigger.ignore', true) INTO _prev_ignore;
                            EXCEPTION WHEN OTHERS …

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@wesleykendall
Comment options

@ikokollari
Comment options

Answer selected by wesleykendall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants