These examples use DNSPython
pip install dnspython
version: "2" | |
services: | |
data: | |
image: busybox:latest | |
volumes: | |
- ./persistent/html:/var/www/html:cached | |
- ./persistent/mail:/var/mail:cached | |
- ./persistent/sql-data:/var/lib/mysql | |
- ./persistent/backup:/var/backup | |
- ./persistent/logs/apache:/var/apache2/logs |
These examples use DNSPython
pip install dnspython
python scrapy-simple-processor.py https://example.com --output-file=/path/to/file.csv |
This demonstrates creating a mixin for inlines along with a custom ModelAdmin to inject the instance into the inline for further processing.
One use case is for when you need to override get_field_queryset to filter available options in a dropdown field to limit selection to only those items associated with the parent.
class InstanceAwareInlineMixin(object):
"""
Create a mixin that supports setting an instance.
"""
def __init__(self, *args, **kwargs):
""" | |
This examples shows setting the current user as the default value for a field named 'user' | |
""" | |
class MyInline(admin.TabularInline): | |
def formfield_for_dbfield(self, db_field, request, **kwargs): | |
field = super().formfield_for_dbfield(db_field, request, **kwargs) | |
if db_field.name == 'user': | |
field.initial = request.user | |
return field |