https://github.com/apkawa/django-import-path-field
Django app for store path to module/class/object and resolve it
https://github.com/apkawa/django-import-path-field
Last synced: about 1 month ago
JSON representation
Django app for store path to module/class/object and resolve it
- Host: GitHub
- URL: https://github.com/apkawa/django-import-path-field
- Owner: Apkawa
- License: mit
- Created: 2018-05-07T16:16:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-08T12:56:56.000Z (over 6 years ago)
- Last Synced: 2025-02-26T08:06:03.355Z (over 1 year ago)
- Language: Python
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pypi.python.org/pypi/django-import-path-field)
[](https://travis-ci.org/Apkawa/django-import-path-field)
[](https://codecov.io/gh/Apkawa/django-import-path-field)
[](https://requires.io/github/Apkawa/django-import-path-field/requirements/?branch=master)
[](https://pyup.io/repos/github/Apkawa/django-import-path-field)
[](https://pypi.python.org/pypi/django-import-path-field)
[](LICENSE)
# Installation
```bash
pip install django-import-path-field
```
or from git
```bash
pip install -e git+https://githib.com/Apkawa/django-import-path-field.git#egg=django-import-path-field
```
## Django and python version
| Python
Django | 3.5 | 3.6 | 3.7 | 3.8 |
|:-----------------:|-----|-----|-----|-----|
| 1.8 | ✘ | ✘ | ✘ | ✘ |
| 1.11 | ✔ | ✔ | ✔ | ✘ |
| 2.2 | ✔ | ✔ | ✔ | ✔ |
| 3.0 | ✘ | ✔ | ✔ | ✔ |
# Usage
models.py
```python
from django.db import models
from importpath_field import ImportPathField, ImportPathChoices
class DescriptionClassStrategy:
# Description for class
short_description = 'Strategy description'
@classmethod
def class_method(cls):
return 1
@classmethod
def class_method_description(cls):
"""Class method description"""
return 1
def method(self):
return 3
def example_function_description():
return 1
# Can description for choice
example_function_description.short_description = 'Function description'
IMPORT_CHOICES = ImportPathChoices(
DescriptionClassStrategy,
example_function_description,
)
# Also may add to choice
@IMPORT_CHOICES.register("Example description")
def example_function():
return 1
class ExampleModel(models.Model):
example_class = ImportPathField()
example_class_choices = ImportPathField(choices=IMPORT_CHOICES)
example_class_null = ImportPathField(null=True, blank=True)
```
```python
```
# Contributing
## run example app
```bash
pip install -r requirements-dev.txt
./test/manage.py migrate
./test/manage.py runserver
```
## run tests
```bash
pip install -r requirements-dev.txt
pytest
tox
```
## Update version
```bash
python setup.py bumpversion
```
## publish pypi
```bash
python setup.py publish
```