Package: django-user-fields
django-user-fieldsA Django application that makes user creation of form fields simple, handling everything from form generation to data storage and retrieval.This was initially built forMUN Managerto 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 GuideInstalldjango-user-fields:$ pip install django-user-fieldsAdduser_fieldsto your installed apps:INSTALLED_APPS = (
    ...
    'user_fields',
    ...
)Run a database migration:$ python manage.py migrateCreate anExtendedExtraFieldmodel: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.Add the@initialise_extra_fieldsdecorator to your form:from user_fields.decorators import initialise_extra_fields

@initialise_extra_fields
class ExampleForm(forms.ModelForm):Add theUserFieldMixinto the object(s) you would like to have extra fields:from user_fields.mixins import UserFieldMixin

class ExampleObject(models.Model, UserFieldMixin):Add aUserDataFieldto the object for storage and migrate:from user_fields.models import UserDataField, ExtraField

class ExampleObject(models.Model, UserFieldMixin):

    extra_data = UserDataField()

$ python manage.py migrateNote: Ifextra_datais taken and/or you would like to name the storage field something else, you can defineUSER_FIELDS_ATTR_NAMEin your settings.Create and pass some extra fields to your form:extra_fields = ExtendedExtraField.objects.filter(parameter=something)

form = ExampleForm(... extra_fields=extra_fields, ...)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 FieldsCharFieldCharField With ChoicesTextFieldBooleanFieldEmailFieldFeel free to submit a pull request if you would like to add more fields. Most fields should be relatively easy to add, althoughFileFieldwill be an interesting challenge!ExtraFieldAttributesProper NameNameDescriptionExampleNamenameEquivalent to the HTMLinputname parameter.example-field (slug format)LabellabelDjango form field label (rendered name).Example FieldHelp Texthelp_textDjango form field help text.This is some guidance.RequiredrequiredDjango form field required parameter.True / FalseField Typefield_typeDropdown with all supported fields.CharField (char)Max. Lengthmax_lengthCharField (only) max length.35ChoiceschoicesChoices for theCharField With Choices.Option 1,Option 2,Option 3UserFieldMixinFunctions.retrieve_extra_data(ExtraField, formatted=True/False): Returns the data stored for a given field. If formatted is True, it will return thevaluefor theCharField With Choices, otherwise it will return thekeyof 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 DoImprove documentation.Implement testing.Add support for more fields.