Skip to content

Commit a5a3bf9

Browse files
committed
Iteration over f_expressions example
1 parent 7e1b20b commit a5a3bf9

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

styleguide_example/blog_examples/f_expressions/db_functions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
from django.db.models.expressions import Func
33
from django.db.models.functions import Cast
44

5-
"""
6-
An F() object represents the value of a model field, transformed value of a model field, or annotated column.
7-
It makes it possible to refer to model field values and perform database operations using them without actually
8-
having to pull them out of the database into Python memory.
9-
"""
10-
115

126
class JSONIncrement(Func):
7+
"""
8+
This is an example from this blog post
9+
- https://www.hacksoft.io/blog/django-jsonfield-incrementation-with-f-expressions
10+
Django docs reference
11+
- https://docs.djangoproject.com/en/4.2/ref/models/expressions/#f-expressions
12+
"""
13+
1314
function = "jsonb_set"
1415

1516
def __init__(self, full_path, value=1, **extra):

styleguide_example/blog_examples/f_expressions/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from django.db import models
22

3-
"""
4-
This is a basic model used to illustrate
5-
JSON field increment with f expressions
6-
"""
7-
83

94
class SomeDataModel(models.Model):
5+
"""
6+
This is an example from this blog post
7+
- https://www.hacksoft.io/blog/django-jsonfield-incrementation-with-f-expressions
8+
"""
9+
1010
name = models.CharField(
1111
max_length=255,
1212
blank=True,

0 commit comments

Comments
 (0)