Quickly create admin related actions, list properties and single instance properties for Django
Project description
#Django admin methods
Easily create [admin actions](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/actions/) methods, [list field methods](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display) and [model methods](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fields) for Django ModelAdmin
##Common usage
Use to quickly create Django admin items such as:
- *"Set as published"*, *"Set as unpublished"* actions in the admin list view
- Shortened descpription (limit to *n* characters) for use in the admin list view
- Image thumbnail in change view
## API
###Actions
The *actions* module provides methods to build [admin actions](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/actions/) and should be used within a **admin.ModelAdmin** declaration
#### true_false(field_name, true_name='', false_name='')
Returns two functions, one to set the model's *field_name* as true, one as false.
If *true_name* is given it will be used as the *short_description* value on the "true" function (which will be shown in the admin actions list).
If no name is given, defaults to *"Set as [field_name]"* and *"Set as non-[field_name]"
##### Sample code
```python
import admin_methods.actions
class PropertyAdmin(admin.ModelAdmin):
set_published, set_unpublished = admin_methods.actions.true_false('published')
set_highlighted, set_unhighlighted = admin_methods.actions.true_false('highlighted')
actions = [set_published, set_unpublished, set_highlighted, set_unhighlighted]
```
Results in the actions below which would set the selected items' *published* value to true or false
![admin actions](https://cloud.githubusercontent.com/assets/487758/6201646/5da29110-b4f0-11e4-9b28-645906e4d2e0.png)
#### toggle(field_name, name='')
Returns a function which sets the model's *field_name* as the opposite of its current value for each selected items.
If *name* is given it will be used as the *short_description* value on the function (which will be shown in the admin actions list).
If no name is given, defaults to *"Toggle [field_name]"*
### List
The *list* module provides methods to create extra fields for use in the list view and should be used within a **admin.ModelAdmin** declaration
#### short_text(field_name, length=200, name='', suffix='...', strip_html=False)
Returns a function to be used as a *list_display* entry.
If no name is given, *field_name* is used.
You may change the suffix which will be appended to **shortened** text only.
Use *strip_html* to remove HTML tags **before** length calculation
```python
import admin_methods.list
class PropertyAdmin(admin.ModelAdmin):
list_display = ('short_description',)
short_description = admin_methods.list.short_text('description', length=150, strip_html=True)
```
Description will be shortened to 150 characters where necessary:
![shortened text](https://cloud.githubusercontent.com/assets/487758/6201671/27c5ff4e-b4f2-11e4-878c-1c258f50f44c.png)
*Strip html* transforms this
![nostrip](https://cloud.githubusercontent.com/assets/487758/6201670/27c4228c-b4f2-11e4-9611-b2696c3fd66e.png)
into this
![stripped](https://cloud.githubusercontent.com/assets/487758/6201672/27c76794-b4f2-11e4-93d7-96a576285604.png)
### Model
The *model* module provides methods to create extra fields for use in the add or change view and should be used within a **models.Model** declaration
#### image_thumb(field_name, name='', width=100, description=False, if_no_image='')
Returns a function to be set on a model, which can then be used in the *fields* and *readonly_fields* declaration of a ModelAdmin
#####Parameters
| Parameter | Default | Description |
|-------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| field_name | | the model ImageField name |
| name | '' | the name for the function. Will be set to the field_name if not provided. <br>**Note** Django needs a name to detect unique methods, but you can make sure that it does not get displayed on the page by setting description to False (default) |
| width | 100 | image width |
| description | False | set *name* as short_description (and hence show it on the page) or not |
| if_no_image | '' | value to display if no image is found |
##### Sample code
**models.py**
```python
class Property(django.db.models.Model):
top_image = django.db.models.ImageField(max_length=255, upload_to='properties/top')
# Admin fields
top_image_preview = admin_actions.model.image_thumb('top_image')
```
**admin.py**
```python
class PropertyAdmin(admin.ModelAdmin):
fields = ('top_image', 'top_image_preview',)
readonly_fields = ('top_image_preview',)
```
**Result**
![image thumb](https://cloud.githubusercontent.com/assets/487758/6201736/b9a489e6-b4f5-11e4-8ac3-da43a75fe5d1.png)
## Dependencies
- Uses [html2text](https://github.com/aaronsw/html2text) for stripping html in *list.short_text*
## Releases
###0.1.2
Changelog
- Improved README
###0.1.1
Changelog
- Improved README
###0.1.0
Initial release
## TODO
- Testing!
Easily create [admin actions](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/actions/) methods, [list field methods](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display) and [model methods](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fields) for Django ModelAdmin
##Common usage
Use to quickly create Django admin items such as:
- *"Set as published"*, *"Set as unpublished"* actions in the admin list view
- Shortened descpription (limit to *n* characters) for use in the admin list view
- Image thumbnail in change view
## API
###Actions
The *actions* module provides methods to build [admin actions](https://docs.djangoproject.com/en/1.7/ref/contrib/admin/actions/) and should be used within a **admin.ModelAdmin** declaration
#### true_false(field_name, true_name='', false_name='')
Returns two functions, one to set the model's *field_name* as true, one as false.
If *true_name* is given it will be used as the *short_description* value on the "true" function (which will be shown in the admin actions list).
If no name is given, defaults to *"Set as [field_name]"* and *"Set as non-[field_name]"
##### Sample code
```python
import admin_methods.actions
class PropertyAdmin(admin.ModelAdmin):
set_published, set_unpublished = admin_methods.actions.true_false('published')
set_highlighted, set_unhighlighted = admin_methods.actions.true_false('highlighted')
actions = [set_published, set_unpublished, set_highlighted, set_unhighlighted]
```
Results in the actions below which would set the selected items' *published* value to true or false
![admin actions](https://cloud.githubusercontent.com/assets/487758/6201646/5da29110-b4f0-11e4-9b28-645906e4d2e0.png)
#### toggle(field_name, name='')
Returns a function which sets the model's *field_name* as the opposite of its current value for each selected items.
If *name* is given it will be used as the *short_description* value on the function (which will be shown in the admin actions list).
If no name is given, defaults to *"Toggle [field_name]"*
### List
The *list* module provides methods to create extra fields for use in the list view and should be used within a **admin.ModelAdmin** declaration
#### short_text(field_name, length=200, name='', suffix='...', strip_html=False)
Returns a function to be used as a *list_display* entry.
If no name is given, *field_name* is used.
You may change the suffix which will be appended to **shortened** text only.
Use *strip_html* to remove HTML tags **before** length calculation
```python
import admin_methods.list
class PropertyAdmin(admin.ModelAdmin):
list_display = ('short_description',)
short_description = admin_methods.list.short_text('description', length=150, strip_html=True)
```
Description will be shortened to 150 characters where necessary:
![shortened text](https://cloud.githubusercontent.com/assets/487758/6201671/27c5ff4e-b4f2-11e4-878c-1c258f50f44c.png)
*Strip html* transforms this
![nostrip](https://cloud.githubusercontent.com/assets/487758/6201670/27c4228c-b4f2-11e4-9611-b2696c3fd66e.png)
into this
![stripped](https://cloud.githubusercontent.com/assets/487758/6201672/27c76794-b4f2-11e4-93d7-96a576285604.png)
### Model
The *model* module provides methods to create extra fields for use in the add or change view and should be used within a **models.Model** declaration
#### image_thumb(field_name, name='', width=100, description=False, if_no_image='')
Returns a function to be set on a model, which can then be used in the *fields* and *readonly_fields* declaration of a ModelAdmin
#####Parameters
| Parameter | Default | Description |
|-------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| field_name | | the model ImageField name |
| name | '' | the name for the function. Will be set to the field_name if not provided. <br>**Note** Django needs a name to detect unique methods, but you can make sure that it does not get displayed on the page by setting description to False (default) |
| width | 100 | image width |
| description | False | set *name* as short_description (and hence show it on the page) or not |
| if_no_image | '' | value to display if no image is found |
##### Sample code
**models.py**
```python
class Property(django.db.models.Model):
top_image = django.db.models.ImageField(max_length=255, upload_to='properties/top')
# Admin fields
top_image_preview = admin_actions.model.image_thumb('top_image')
```
**admin.py**
```python
class PropertyAdmin(admin.ModelAdmin):
fields = ('top_image', 'top_image_preview',)
readonly_fields = ('top_image_preview',)
```
**Result**
![image thumb](https://cloud.githubusercontent.com/assets/487758/6201736/b9a489e6-b4f5-11e4-8ac3-da43a75fe5d1.png)
## Dependencies
- Uses [html2text](https://github.com/aaronsw/html2text) for stripping html in *list.short_text*
## Releases
###0.1.2
Changelog
- Improved README
###0.1.1
Changelog
- Improved README
###0.1.0
Initial release
## TODO
- Testing!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-admin-methods-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b8993b6013d769dad18407d7c92f56b269afb801111945e1cc1a8b5b460e1ad |
|
MD5 | 478421f324895b2e4cc5472005a44014 |
|
BLAKE2b-256 | 56756ededf486648eb78590935a552b2abc27151a068f857eb587d9c51c14722 |
Close
Hashes for django_admin_methods-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a81ac31c444df841f7ee0999abd24367e30487634d7275ee0e149a3dc4a55100 |
|
MD5 | efdee4f2771de58e85532299b0ac7bd9 |
|
BLAKE2b-256 | 9ff49e27b8a88fac3c359f439fe8478fefb486a03a8e36ab41c4b3ed22d777d3 |