From 3827c50bd51fdaca4d300d3dc0c24e1de47a6e90 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Tue, 21 May 2024 17:01:21 +0200 Subject: [PATCH 1/4] Added [dev] optional install target --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index b5eef70..ce943ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,3 +24,6 @@ testproject = [ "model-bakery", "time-machine", ] +dev = [ + "black<24.5.0" +] From db7322ca27dc756c8a2dbb2739e478271cdf433e Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Tue, 21 May 2024 17:03:09 +0200 Subject: [PATCH 2/4] Deleted migration files for testapp The migrations are not needed since those models are meant to live in a temporary database that gets recreated every test run. This will also make black formatting less noisy. --- .../testapp/migrations/0001_initial.py | 33 ------------------- testproject/testapp/migrations/__init__.py | 0 2 files changed, 33 deletions(-) delete mode 100644 testproject/testapp/migrations/0001_initial.py delete mode 100644 testproject/testapp/migrations/__init__.py diff --git a/testproject/testapp/migrations/0001_initial.py b/testproject/testapp/migrations/0001_initial.py deleted file mode 100644 index 04c5682..0000000 --- a/testproject/testapp/migrations/0001_initial.py +++ /dev/null @@ -1,33 +0,0 @@ -# Generated by Django 5.0.6 on 2024-05-09 15:04 - -import datetime -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Book', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=100)), - ('rating', models.IntegerField(blank=True, null=True)), - ('published', models.DateField(default=datetime.date.today)), - ('has_cover', models.BooleanField(default=True)), - ], - ), - migrations.CreateModel( - name='Person', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=100)), - ('birth', models.DateField(default=datetime.date.today)), - ], - ), - ] diff --git a/testproject/testapp/migrations/__init__.py b/testproject/testapp/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 From 75a8187cfc7eebd0edb647e4b1444c7b0b0e3b1c Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Tue, 21 May 2024 17:12:38 +0200 Subject: [PATCH 3/4] Added black check to CI --- .github/workflows/black.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 0000000..6d5aa97 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,15 @@ +name: Black + +on: [pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' # 3.11 needed for black's use_pyproject + - uses: psf/black@stable + with: + use_pyproject: true From 2d65903be6d153c82ccd59a9fbb35d5632b95992 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Tue, 21 May 2024 17:35:56 +0200 Subject: [PATCH 4/4] Reformatted code with black --- src/modelsubquery/functions.py | 5 +++-- testproject/manage.py | 4 ++-- testproject/testproject/settings.py | 14 +++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/modelsubquery/functions.py b/src/modelsubquery/functions.py index a39ea6b..33652bc 100644 --- a/src/modelsubquery/functions.py +++ b/src/modelsubquery/functions.py @@ -1,6 +1,7 @@ """ Tools to build subqueries that produce model instances """ + from django.db import models from django.db.models.constants import LOOKUP_SEP from django.db.models.functions import JSONObject @@ -26,6 +27,7 @@ class JSONModelField(models.JSONField): Any missing fields in the JSON object are marked as "deferred" (and will be loaded from the db on access). """ + # TODO: support the "pk" alias # TODO: support fk fields (recursive __ access) def __init__(self, model, *args, **kwargs): @@ -70,6 +72,5 @@ def ModelSubquery(queryset, fields=None): """ jsonobj = model_to_json(queryset.model, fields=fields) return models.Subquery( - queryset.values_list(jsonobj), - output_field=JSONModelField(queryset.model) + queryset.values_list(jsonobj), output_field=JSONModelField(queryset.model) ) diff --git a/testproject/manage.py b/testproject/manage.py index 6253a24..8bd034f 100755 --- a/testproject/manage.py +++ b/testproject/manage.py @@ -6,7 +6,7 @@ def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testproject.settings') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: @@ -18,5 +18,5 @@ def main(): execute_from_command_line(sys.argv) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/testproject/testproject/settings.py b/testproject/testproject/settings.py index 7202ec5..2bc4dd3 100644 --- a/testproject/testproject/settings.py +++ b/testproject/testproject/settings.py @@ -2,21 +2,21 @@ BASE_DIR = Path(__file__).resolve().parent.parent -SECRET_KEY = 'insecure' +SECRET_KEY = "insecure" DEBUG = True INSTALLED_APPS = [ - 'testapp', + "testapp", ] DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", } } -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_TZ = True -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"