def METHOD_NAME(self):
    q = Q(
        Q(char_null="80"),
        ~Q(Q(char__lt="5"), Q(char__gt="50"), join_type="OR"),
        join_type="AND",
    )
    r = q.resolve(CharFields, CharFields._meta.basequery)
    self.assertEqual(
        r.where_criterion.get_sql(),
        "\"char_null\"='80' AND NOT (\"char\"<'5' OR \"char\">'50')",
    )