Fix alternate misspellings

This commit is contained in:
feyrkh 2024-09-29 02:03:35 -05:00 committed by GitHub
parent f68e1884eb
commit 10e4f989f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -192,7 +192,7 @@ Don't confuse database fields with [Attributes](../../../Components/Attributes.m
- **Line 7**: ... We also want only Characters with `Attributes` whose `db_key` is exactly `"lycanthropy"`
- **Line 8** :... at the same time as the `Attribute`'s `db_value` is exactly 2.
Running this query makes our newly lycantrophic Character appear in `will_transform` so we know to transform it. Success!
Running this query makes our newly lycanthropic Character appear in `will_transform` so we know to transform it. Success!
```{important}
You can't query for an Attribute `db_value` quite as freely as other data-types. This is because Attributes can store any Python entity and is actually stored as _strings_ on the database side. So while you can use `__eq=2` in the above example, you will not be able to `__gt=2` or `__lt=2` because these operations don't make sense for strings. See [Attributes](../../../Components/Attributes.md#querying-by-attribute) for more information on dealing with Attributes.
@ -201,7 +201,7 @@ You can't query for an Attribute `db_value` quite as freely as other data-types.
## Queries with OR or NOT
All examples so far used `AND` relations. The arguments to `.filter` are added together with `AND`
("we want tag room to be "monlit" _and_ lycantrhopy be > 2").
("we want tag room to be "monlit" _and_ lycanthropy be > 2").
For queries using `OR` and `NOT` we need Django's [Q object](https://docs.djangoproject.com/en/4.1/topics/db/queries/#complex-lookups-with-q-objects). It is imported from Django directly:
@ -228,7 +228,7 @@ works like `NOT`.
Would get all Characters that are either named "Dalton" _or_ which is _not_ in prison. The result is a mix
of Daltons and non-prisoners.
Let us expand our original werewolf query. Not only do we want to find all Characters in a moonlit room with a certain level of `lycanthrophy` - we decide that if they have been _newly bitten_, they should also turn, _regardless_ of their lycanthropy level (more dramatic that way!).
Let us expand our original werewolf query. Not only do we want to find all Characters in a moonlit room with a certain level of `lycanthropy` - we decide that if they have been _newly bitten_, they should also turn, _regardless_ of their lycanthropy level (more dramatic that way!).
Let's say that getting bitten means that you'll get assigned a Tag `recently_bitten`.
@ -256,12 +256,12 @@ That's quite compact. It may be easier to see what's going on if written this wa
from django.db.models import Q
q_moonlit = Q(db_location__db_tags__db_key__iexact="moonlit")
q_lycantropic = Q(db_attributes__db_key="lycanthropy", db_attributes__db_value__eq=2)
q_lycanthropic = Q(db_attributes__db_key="lycanthropy", db_attributes__db_value__eq=2)
q_recently_bitten = Q(db_tags__db_key__iexact="recently_bitten")
will_transform = (
Character.objects
.filter(q_moonlit & (q_lycantropic | q_recently_bitten))
.filter(q_moonlit & (q_lycanthropic | q_recently_bitten))
.distinct()
)
```