Skip to main content

A Django application that makes user creation of form fields simple.

Project description

django-user-fields

Total downloads PyPI version

A Django application that makes user creation of form fields simple, handling everything from form generation to data storage and retrieval.

This was initially built for MUN Manager to allow conferences to collect whatever information they wanted to during all parts of the registration process. django-user-fields allows conferences to easily add their own extra fields to various forms using a simple admin interface creating a tailored experience.

Simple Installation and Usage Guide

  1. Install django-user-fields:

$ pip install django-user-fields
  1. Add user_fields to your installed apps:

INSTALLED_APPS = (
    ...
    'user_fields',
    ...
)
  1. Run a database migration:

$ python manage.py migrate
  1. Create an ExtendedExtraField model:

from user_fields.models import ExtraField

class ExtendedExtraField(ExtraField):

    # You can add any custom fields you'd like here to make filtering fields easier.
    # A list of all predefined fields can be found below.
  1. Add the @initialise_extra_fields decorator to your form:

from user_fields.decorators import initialise_extra_fields

@initialise_extra_fields
class ExampleForm(forms.ModelForm):
  1. Add the UserFieldMixin to the object(s) you would like to have extra fields:

from user_fields.mixins import UserFieldMixin

class ExampleObject(models.Model, UserFieldMixin):
  1. Add a UserDataField to the object for storage and migrate:

from user_fields.models import UserDataField, ExtraField

class ExampleObject(models.Model, UserFieldMixin):

    extra_data = UserDataField()

$ python manage.py migrate

Note: If extra_data is taken and/or you would like to name the storage field something else, you can define USER_FIELDS_ATTR_NAME in your settings.

  1. Create and pass some extra fields to your form:

extra_fields = ExtendedExtraField.objects.filter(parameter=something)

form = ExampleForm(... extra_fields=extra_fields, ...)
  1. Add an extra line to save the extra fields to your object:

object = form.save()
object.save_extra_form_data(form) # Ensures that both object and form save functions are not overwritten.

Supported Fields

  • CharField

  • CharField With Choices

  • TextField

  • BooleanField

  • EmailField

Feel free to submit a pull request if you would like to add more fields. Most fields should be relatively easy to add, although FileField will be an interesting challenge!

ExtraField Attributes

Proper Name

Name

Description

Example

Name

name

Equivalent to the HTML input name parameter.

example-field (slug format)

Label

label

Django form field label (rendered name).

Example Field

Help Text

help_text

Django form field help text.

This is some guidance.

Required

required

Django form field required parameter.

True / False

Field Type

field_type

Dropdown with all supported fields.

CharField (char)

Max. Length

max_length

CharField (only) max length.

35

Choices

choices

Choices for the CharField With Choices.

Option 1,Option 2,Option 3

UserFieldMixin Functions

.retrieve_extra_data(ExtraField, formatted=True/False): Returns the data stored for a given field. If formatted is True, it will return the value for the CharField With Choices, otherwise it will return the key of the choice.

.save_extra_data(ExtraField, data): Saves the data supplied for a given field to the object.

.save_extra_form_data(Form): Saves all of the extra field data in a form to the object.

.delete_extra_data(ExtraField): Deletes all of the data associated with a given field.

To Do

  • Improve documentation.

  • Implement testing.

  • Add support for more fields.

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

django-user-fields-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

django_user_fields-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file django-user-fields-0.1.1.tar.gz.

File metadata

  • Download URL: django-user-fields-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for django-user-fields-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8931c7070b10ab58d936a9b50ca01c0b1a3ed70a3f595ec23bd282c8bb523db8
MD5 7da06efca43fa3b4de95d7e86e0f5726
BLAKE2b-256 e9f56fd3fc2cee5eff4f6710eeddc6bf465514acf53ad029dc8fa5c3843b6d9e

See more details on using hashes here.

File details

Details for the file django_user_fields-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_user_fields-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for django_user_fields-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6644673815717d6970147b58f70f765859f5717e177ae3c2c15c2fd695da6651
MD5 c00966ed3e5d8e80e3e93821b5a3cc34
BLAKE2b-256 3d8b9fcd2c1a6dab9d000bd4e64e48ea18039a4871a7599bd7de722e429d68a0

See more details on using hashes here.

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