Skip to main content

Django-Hacker: customize default django forms

Project description

Basic usage

Install with pip install djhacker and then:

import djhacker

djhacker.formfield(
    YourModel.your_field,
    YourFormField,
    custom_form_field_kwarg='something',
)

This will make any Django ModelForm render a YourFormField(custom_form_field_kwarg='something') by default, plus whatever other kwargs it wants to add, you won’t have to use any specific model form, this will work natively in the admin for instance.

Registry

You can register custom form field for model field types:

@djhacker.register(models.ForeignKey)
def custom_fk_formfield(model_field, **kwargs):
    return YourFormField, {
        'custom_form_field_kwarg': 'something',
        **kwargs,
    )

# you don't need to pass extra arguments anymore for ForeignKey fields:
djhacker.formfield(YourModel.some_fk, queryset=Some.objects.all())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djhacker-0.1.1.tar.gz (2.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page