django-nx 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_nx-0.1.0/.gitignore +218 -0
- django_nx-0.1.0/LICENSE +21 -0
- django_nx-0.1.0/PKG-INFO +12 -0
- django_nx-0.1.0/README.md +2 -0
- django_nx-0.1.0/nx/__init__.py +0 -0
- django_nx-0.1.0/nx/models/__init__.py +0 -0
- django_nx-0.1.0/nx/models/fields.py +320 -0
- django_nx-0.1.0/nx/nx.py +32 -0
- django_nx-0.1.0/nx/restframework/__init__.py +0 -0
- django_nx-0.1.0/nx/restframework/serializers.py +5 -0
- django_nx-0.1.0/pyproject.toml +20 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
# Temporary file for partial code execution
|
|
204
|
+
tempCodeRunnerFile.py
|
|
205
|
+
|
|
206
|
+
# Ruff stuff:
|
|
207
|
+
.ruff_cache/
|
|
208
|
+
|
|
209
|
+
# PyPI configuration file
|
|
210
|
+
.pypirc
|
|
211
|
+
|
|
212
|
+
# Marimo
|
|
213
|
+
marimo/_static/
|
|
214
|
+
marimo/_lsp/
|
|
215
|
+
__marimo__/
|
|
216
|
+
|
|
217
|
+
# Streamlit
|
|
218
|
+
.streamlit/secrets.toml
|
django_nx-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Josh Yu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
django_nx-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-nx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight Django field utilities and extensions
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: django<6.1,>=3.2
|
|
8
|
+
Requires-Dist: djangorestframework<3.18,>=3.12.4
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# django-nx
|
|
12
|
+
django-nx — Lightweight Django field utilities and extensions
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Custom Django model fields with enhanced defaults and behaviors.
|
|
3
|
+
|
|
4
|
+
This module provides extended versions of Django's model fields with:
|
|
5
|
+
|
|
6
|
+
- Automatic help_text generation from verbose_name
|
|
7
|
+
- Sensible default values for common use cases
|
|
8
|
+
- Specialized fields for money/decimal amounts
|
|
9
|
+
- Choice field variants for integer and text options
|
|
10
|
+
|
|
11
|
+
Available Fields
|
|
12
|
+
----------------
|
|
13
|
+
|
|
14
|
+
:CharField: CharField with empty string default and auto help_text
|
|
15
|
+
:IntegerField: IntegerField with auto help_text support
|
|
16
|
+
:MoneyField: DecimalField configured for monetary amounts
|
|
17
|
+
:TextField: TextField with empty string default and auto help_text
|
|
18
|
+
:BooleanField: BooleanField defaulting to False
|
|
19
|
+
:IntChoiceField: SmallIntegerField for choice options
|
|
20
|
+
:TextChoiceField: CharField for text-based choices
|
|
21
|
+
:ForeignKey: ForeignKey with null/blank defaults
|
|
22
|
+
:OneToOne: OneToOneField with null/blank defaults
|
|
23
|
+
:ManyToMany: ManyToManyField with null/blank defaults
|
|
24
|
+
:ObjectField: JSONField defaulting to empty dict
|
|
25
|
+
:ArrayField: JSONField defaulting to empty list
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from decimal import Decimal
|
|
29
|
+
|
|
30
|
+
from django.db import models
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CharField(models.CharField):
|
|
34
|
+
"""
|
|
35
|
+
A CharField that defaults to an empty string and allows blank values.
|
|
36
|
+
This is useful for character fields where you want to avoid NULL values in the database
|
|
37
|
+
and have a consistent empty string as the default.
|
|
38
|
+
|
|
39
|
+
If help_text is not provided, it will use the verbose_name as help_text.
|
|
40
|
+
|
|
41
|
+
default max_length is 128
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, *args, **kwargs):
|
|
45
|
+
kwargs.setdefault("default", "")
|
|
46
|
+
kwargs.setdefault("blank", True)
|
|
47
|
+
kwargs.setdefault("max_length", 128)
|
|
48
|
+
|
|
49
|
+
# If help_text not provided, use verbose_name when available
|
|
50
|
+
if "help_text" not in kwargs and "verbose_name" in kwargs:
|
|
51
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
52
|
+
|
|
53
|
+
super().__init__(*args, **kwargs)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class IntegerField(models.IntegerField):
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
If help_text is not provided, it will use the verbose_name as help_text.
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(self, *args, **kwargs):
|
|
64
|
+
# If help_text is not provided, use verbose_name as help_text
|
|
65
|
+
if "help_text" not in kwargs and "verbose_name" in kwargs:
|
|
66
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
67
|
+
|
|
68
|
+
super().__init__(*args, **kwargs)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class MoneyField(models.DecimalField):
|
|
72
|
+
"""
|
|
73
|
+
MoneyField for monetary amounts using DECIMAL under the hood.
|
|
74
|
+
|
|
75
|
+
:param verbose_name: Human-readable name for the field
|
|
76
|
+
:param max_digits: Maximum number of digits (default: 18)
|
|
77
|
+
:param decimal_places: Number of decimal places (default: 2)
|
|
78
|
+
:param default: Default value (default: Decimal('0'))
|
|
79
|
+
|
|
80
|
+
Example::
|
|
81
|
+
|
|
82
|
+
amount = MoneyField('金额')
|
|
83
|
+
tax = MoneyField('税额', max_digits=14, decimal_places=4)
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
def __init__(self, verbose_name=None, *args, **kwargs):
|
|
87
|
+
# Sensible defaults; allow override by explicit kwargs
|
|
88
|
+
kwargs["max_digits"] = kwargs.get("max_digits", 18)
|
|
89
|
+
kwargs["decimal_places"] = kwargs.get("decimal_places", 2)
|
|
90
|
+
kwargs["default"] = kwargs.get("default", Decimal("0"))
|
|
91
|
+
|
|
92
|
+
# If help_text not provided, mirror verbose_name when available
|
|
93
|
+
if (
|
|
94
|
+
"help_text" not in kwargs
|
|
95
|
+
and "verbose_name" in kwargs
|
|
96
|
+
and kwargs["verbose_name"]
|
|
97
|
+
):
|
|
98
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
99
|
+
|
|
100
|
+
super().__init__(verbose_name, *args, **kwargs)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class TextField(models.TextField):
|
|
104
|
+
"""
|
|
105
|
+
A TextField that defaults to an empty string and allows blank values.
|
|
106
|
+
This is useful for character fields where you want to avoid NULL values in the database
|
|
107
|
+
and have a consistent empty string as the default.
|
|
108
|
+
|
|
109
|
+
If help_text is not provided, it will use the verbose_name as help_text.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
def __init__(self, *args, **kwargs):
|
|
113
|
+
kwargs.setdefault("default", "")
|
|
114
|
+
kwargs.setdefault("blank", True)
|
|
115
|
+
|
|
116
|
+
# If help_text not provided, use verbose_name when available
|
|
117
|
+
if "help_text" not in kwargs and "verbose_name" in kwargs:
|
|
118
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
119
|
+
|
|
120
|
+
super().__init__(*args, **kwargs)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class BooleanField(models.BooleanField):
|
|
124
|
+
def __init__(self, *args, **kwargs):
|
|
125
|
+
kwargs.setdefault("default", False)
|
|
126
|
+
kwargs.setdefault("blank", True)
|
|
127
|
+
|
|
128
|
+
# If help_text not provided, use verbose_name when available
|
|
129
|
+
if "help_text" not in kwargs and "verbose_name" in kwargs:
|
|
130
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
131
|
+
|
|
132
|
+
super().__init__(*args, **kwargs)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class IntChoiceField(models.SmallIntegerField):
|
|
136
|
+
"""
|
|
137
|
+
A SmallIntegerField that present as Choice Field.
|
|
138
|
+
|
|
139
|
+
If help_text is not provided, it will use the verbose_name as help_text.
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
def __init__(self, verbose_name=None, choices=None, *args, **kwargs):
|
|
143
|
+
if choices is not None:
|
|
144
|
+
kwargs["choices"] = choices
|
|
145
|
+
|
|
146
|
+
# If help_text not provided, use verbose_name when available
|
|
147
|
+
if "help_text" not in kwargs and verbose_name is not None:
|
|
148
|
+
kwargs["help_text"] = verbose_name
|
|
149
|
+
|
|
150
|
+
super().__init__(verbose_name, *args, **kwargs)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class TextChoiceField(models.CharField):
|
|
154
|
+
"""
|
|
155
|
+
A CharField that present as Choice Field.
|
|
156
|
+
|
|
157
|
+
If help_text is not provided, it will use the verbose_name as help_text.
|
|
158
|
+
|
|
159
|
+
Default `max_length` is 64
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
def __init__(self, verbose_name=None, choices=None, *args, **kwargs):
|
|
163
|
+
if choices is not None:
|
|
164
|
+
kwargs["choices"] = choices
|
|
165
|
+
kwargs.setdefault("max_length", 64) # Default max length for choice fields
|
|
166
|
+
|
|
167
|
+
# If help_text not provided, use verbose_name when available
|
|
168
|
+
if "help_text" not in kwargs and verbose_name is not None:
|
|
169
|
+
kwargs["help_text"] = verbose_name
|
|
170
|
+
|
|
171
|
+
super().__init__(verbose_name, *args, **kwargs)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class ForeignKey(models.ForeignKey):
|
|
175
|
+
"""
|
|
176
|
+
A ForeignKey that defaults to common settings for reference fields.
|
|
177
|
+
|
|
178
|
+
Defaults:
|
|
179
|
+
- null=True
|
|
180
|
+
- blank=True
|
|
181
|
+
- default=None
|
|
182
|
+
|
|
183
|
+
Usage:
|
|
184
|
+
user = nx.ForeignKey('auth.User', 'user')
|
|
185
|
+
warehouse = nx.ForeignKey('admin_model.KZWareHouse', 'warehouse')
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
def __init__(self, to, verbose_name=None, *args, **kwargs):
|
|
189
|
+
# Sensible defaults for foreign keys
|
|
190
|
+
kwargs.setdefault("null", True)
|
|
191
|
+
kwargs.setdefault("blank", True)
|
|
192
|
+
kwargs.setdefault("default", None)
|
|
193
|
+
|
|
194
|
+
# If help_text not provided, use verbose_name when available
|
|
195
|
+
if verbose_name:
|
|
196
|
+
kwargs["verbose_name"] = verbose_name
|
|
197
|
+
if (
|
|
198
|
+
"help_text" not in kwargs
|
|
199
|
+
and "verbose_name" in kwargs
|
|
200
|
+
and kwargs["verbose_name"]
|
|
201
|
+
):
|
|
202
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
203
|
+
|
|
204
|
+
super().__init__(to, *args, **kwargs)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class OneToOne(models.OneToOneField):
|
|
208
|
+
"""
|
|
209
|
+
A OneToOneField that defaults to common settings for reference fields.
|
|
210
|
+
|
|
211
|
+
Defaults:
|
|
212
|
+
- null=True
|
|
213
|
+
- blank=True
|
|
214
|
+
- default=None
|
|
215
|
+
|
|
216
|
+
Usage:
|
|
217
|
+
user = nx.OneToOne('auth.User', 'user')
|
|
218
|
+
warehouse = nx.OneToOne('admin_model.KZWareHouse', 'warehouse')
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
def __init__(self, to, verbose_name=None, *args, **kwargs):
|
|
222
|
+
# Sensible defaults for foreign keys
|
|
223
|
+
kwargs.setdefault("null", True)
|
|
224
|
+
kwargs.setdefault("blank", True)
|
|
225
|
+
kwargs.setdefault("default", None)
|
|
226
|
+
|
|
227
|
+
# If help_text not provided, use verbose_name when available
|
|
228
|
+
if verbose_name:
|
|
229
|
+
kwargs["verbose_name"] = verbose_name
|
|
230
|
+
if (
|
|
231
|
+
"help_text" not in kwargs
|
|
232
|
+
and "verbose_name" in kwargs
|
|
233
|
+
and kwargs["verbose_name"]
|
|
234
|
+
):
|
|
235
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
236
|
+
|
|
237
|
+
super().__init__(to, *args, **kwargs)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class ManyToMany(models.ManyToManyField):
|
|
241
|
+
"""
|
|
242
|
+
A ManyToManyField that defaults to common settings for reference fields.
|
|
243
|
+
|
|
244
|
+
Defaults:
|
|
245
|
+
- null=True
|
|
246
|
+
- blank=True
|
|
247
|
+
- default=None
|
|
248
|
+
|
|
249
|
+
Usage:
|
|
250
|
+
user = nx.ManyToMany('auth.User', 'user')
|
|
251
|
+
warehouse = nx.ManyToMany('admin_model.KZWareHouse', 'warehouse')
|
|
252
|
+
"""
|
|
253
|
+
|
|
254
|
+
def __init__(self, to, verbose_name=None, *args, **kwargs):
|
|
255
|
+
# Sensible defaults for foreign keys
|
|
256
|
+
kwargs.setdefault("null", True)
|
|
257
|
+
kwargs.setdefault("blank", True)
|
|
258
|
+
kwargs.setdefault("default", None)
|
|
259
|
+
|
|
260
|
+
# If help_text not provided, use verbose_name when available
|
|
261
|
+
if verbose_name:
|
|
262
|
+
kwargs["verbose_name"] = verbose_name
|
|
263
|
+
if (
|
|
264
|
+
"help_text" not in kwargs
|
|
265
|
+
and "verbose_name" in kwargs
|
|
266
|
+
and kwargs["verbose_name"]
|
|
267
|
+
):
|
|
268
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
269
|
+
|
|
270
|
+
super().__init__(to, *args, **kwargs)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class ObjectField(models.JSONField):
|
|
274
|
+
"""
|
|
275
|
+
A JSONField that defaults to common settings for reference fields.
|
|
276
|
+
|
|
277
|
+
Defaults:
|
|
278
|
+
- blank=True
|
|
279
|
+
- default={}
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
def __init__(self, *args, **kwargs):
|
|
283
|
+
# Sensible defaults for foreign keys
|
|
284
|
+
kwargs.setdefault("blank", True)
|
|
285
|
+
kwargs.setdefault("default", dict)
|
|
286
|
+
|
|
287
|
+
# If help_text not provided, use verbose_name when available
|
|
288
|
+
if (
|
|
289
|
+
"help_text" not in kwargs
|
|
290
|
+
and "verbose_name" in kwargs
|
|
291
|
+
and kwargs["verbose_name"]
|
|
292
|
+
):
|
|
293
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
294
|
+
|
|
295
|
+
super().__init__(*args, **kwargs)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
class ArrayField(models.JSONField):
|
|
299
|
+
"""
|
|
300
|
+
A JSONField that defaults to common settings for reference fields.
|
|
301
|
+
|
|
302
|
+
Defaults:
|
|
303
|
+
- blank=True
|
|
304
|
+
- default=[]
|
|
305
|
+
"""
|
|
306
|
+
|
|
307
|
+
def __init__(self, *args, **kwargs):
|
|
308
|
+
# Sensible defaults for foreign keys
|
|
309
|
+
kwargs.setdefault("blank", True)
|
|
310
|
+
kwargs.setdefault("default", list)
|
|
311
|
+
|
|
312
|
+
# If help_text not provided, use verbose_name when available
|
|
313
|
+
if (
|
|
314
|
+
"help_text" not in kwargs
|
|
315
|
+
and "verbose_name" in kwargs
|
|
316
|
+
and kwargs["verbose_name"]
|
|
317
|
+
):
|
|
318
|
+
kwargs["help_text"] = kwargs["verbose_name"]
|
|
319
|
+
|
|
320
|
+
super().__init__(*args, **kwargs)
|
django_nx-0.1.0/nx/nx.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Nx package - Extended Django model fields and utilities.
|
|
3
|
+
|
|
4
|
+
This package provides custom Django model fields with enhanced defaults
|
|
5
|
+
and behaviors, including automatic help_text generation and specialized
|
|
6
|
+
field types for common use cases.
|
|
7
|
+
|
|
8
|
+
Quick Start
|
|
9
|
+
-----------
|
|
10
|
+
|
|
11
|
+
Import fields directly from the nx package::
|
|
12
|
+
|
|
13
|
+
from nx import nx
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from .models.fields import (
|
|
19
|
+
CharField,
|
|
20
|
+
IntegerField,
|
|
21
|
+
TextField,
|
|
22
|
+
BooleanField,
|
|
23
|
+
IntChoiceField,
|
|
24
|
+
TextChoiceField,
|
|
25
|
+
MoneyField,
|
|
26
|
+
ForeignKey,
|
|
27
|
+
OneToOne,
|
|
28
|
+
ManyToMany,
|
|
29
|
+
ObjectField,
|
|
30
|
+
ArrayField,
|
|
31
|
+
)
|
|
32
|
+
from . import restframework as drf
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "django-nx"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Lightweight Django field utilities and extensions"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"django>=3.2,<6.1",
|
|
9
|
+
"djangorestframework>=3.12.4,<3.18",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[tool.hatch.build.targets.sdist]
|
|
13
|
+
include = ["nx"]
|
|
14
|
+
|
|
15
|
+
[tool.hatch.build.targets.wheel]
|
|
16
|
+
include = ["nx"]
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["hatchling"]
|
|
20
|
+
build-backend = "hatchling.build"
|