| 14 | {{{ |
| 15 | |
| 16 | ```bash |
| 17 | docker-compose up |
| 18 | |
| 19 | pyenv install 3.8.9 |
| 20 | pyenv local 3.8.9 |
| 21 | python -m venv .env |
| 22 | . .env/bin/activate |
| 23 | pip install -r requirements.txt |
| 24 | |
| 25 | # create the db |
| 26 | psql postgres://ticket32690user:password@127.0.0.1:5432/ -c "create database ticket32690db;" |
| 27 | ./manage.py migrate |
| 28 | ``` |
| 29 | |
| 30 | |
| 31 | |
| 32 | From inside the django shell |
| 33 | |
| 34 | ```example |
| 35 | 07:11:24 (.env) jmunsch@pop-os ticket32690 → ./manage.py shell |
| 36 | Python 3.8.9 (default, Apr 14 2021, 18:54:59) |
| 37 | [GCC 9.3.0] on linux |
| 38 | Type "help", "copyright", "credits" or "license" for more information. |
| 39 | (InteractiveConsole) |
| 40 | >>> from things.models import Actor, RealmAccess, Thing |
| 41 | >>> actor1, _ = Actor.objects.get_or_create(**{}) |
| 42 | >>> actor2, _ = Actor.objects.get_or_create(**{}) |
| 43 | >>> |
| 44 | >>> r1 = RealmAccess.objects.create(name='ok') |
| 45 | >>> r2 = RealmAccess.objects.create(name='ok2') |
| 46 | >>> |
| 47 | >>> actor1.realm_access.add(r1) |
| 48 | >>> |
| 49 | >>> Thing.objects.filter_by_realm_access_broken(actor1) |
| 50 | SELECT "things_thing"."id", |
| 51 | "things_thing"."created", |
| 52 | "things_thing"."updated", |
| 53 | "things_thing"."create_by", |
| 54 | "things_thing"."update_by", |
| 55 | "things_thing"."date", |
| 56 | "things_thing"."average", |
| 57 | "things_thing"."data_points", |
| 58 | "things_thing"."actor_id", |
| 59 | "things_thing"."realms", |
| 60 | COUNT("things_actorrealmaccess"."property_group_id") AS "actor__realm_access__count" |
| 61 | FROM "things_thing" |
| 62 | INNER JOIN "things_actor" ON ("things_thing"."actor_id" = "things_actor"."id") |
| 63 | LEFT OUTER JOIN "things_actorrealmaccess" ON ("things_actor"."id" = "things_actorrealmaccess"."actor_id") |
| 64 | LEFT OUTER JOIN "things_actorrealmaccess" T5 ON ("things_actor"."id" = T5."actor_id") |
| 65 | GROUP BY "things_thing"."id", |
| 66 | T5."property_group_id", |
| 67 | (SELECT U0."id", |
| 68 | U0."created", |
| 69 | U0."updated", |
| 70 | U0."create_by", |
| 71 | U0."update_by", |
| 72 | U0."name" |
| 73 | FROM "things_realmaccess" U0 |
| 74 | INNER JOIN "things_actorrealmaccess" U1 ON (U0."id" = U1."property_group_id") |
| 75 | WHERE U1."actor_id" = 2) |
| 76 | HAVING (T5."property_group_id" IN |
| 77 | (SELECT U0."id" |
| 78 | FROM "things_realmaccess" U0 |
| 79 | INNER JOIN "things_actorrealmaccess" U1 ON (U0."id" = U1."property_group_id") |
| 80 | WHERE U1."actor_id" = 2) |
| 81 | OR COUNT("things_actorrealmaccess"."property_group_id") = 0) |
| 82 | Traceback (most recent call last): |
| 83 | File "/home/jmunsch/PycharmProjects/test-django/.env/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute |
| 84 | return self.cursor.execute(sql, params) |
| 85 | psycopg2.errors.SyntaxError: subquery must return only one column |
| 86 | LINE 1: ...P BY "things_thing"."id", T5."property_group_id", (SELECT U0... |
| 87 | ^ |
| 88 | ``` |
| 89 | }}} |
| 90 | |