Opened 11 years ago

Closed 3 years ago

#27 closed New feature (worksforme)

Single form field for multiple database fields

Reported by: Adrian Holovaty Owned by: nobody
Component: Forms Version:
Severity: Normal Keywords:
Cc: cmawebsite@…, msiedlarek, Alan Justino da Silva, charette.s@…, j.arnds@…, carlos.palol@… Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Some admin interfaces would benefit from being able to have multiple fields' worth of data entered in a single field. For example, a field for a sports stat could be entered into a single field as "XX-YY-ZZ", whereas the three values are actually three separate fields in the DB.

Relevant conversation:

<jacobkm> Well, I'm using those aggregate fields for stats where you type something like "3-17" and it gets split into multiple fields.  I see there's a CommaSeperatedIntegerField in formfields which would work for this, but there needs to be a way in the datadescriptions to say "this group of fields should be presented as a single field"
<django34> The DD will have to provide a format string of some sort
<jacobkm> Easy enough
<jacobkm> are you thinking of a % format string or a regex?
<django34> Not sure...
<django34> Probably just %
<django34> fields_together = '%(last_name)s, %(first_name)s'

Change History (23)

comment:1 Changed 11 years ago by Main

Type: enhancementdefect

comment:2 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedAccepted

I know there have been some newforms examples where multiple form fields are used for a single database field. Is it just as easy to do the opposite, single form field for multiple database fields?

comment:3 Changed 10 years ago by Simon Willison

This would be useful for tagging interfaces as well, where you often want to enter multiple tags separated by spaces.

comment:4 Changed 9 years ago by mir@…

Triage Stage: UnreviewedAccepted

The stage was 'Unreviewed', but from the history it should be 'Accepted'. Probably a spam-removal-relict ... I haven't looked at the details.

comment:5 Changed 9 years ago by Philippe Raoult

Keywords: feature_request added

comment:6 Changed 9 years ago by Collin Anderson

Component: Metasystemdjango.newforms
Summary: Create an admin-input format string frameworkSingle form field for multiple database fields
Triage Stage: AcceptedUnreviewed

Seems to me this is a newforms limitation.

comment:7 Changed 9 years ago by Collin Anderson

Cc: cmawebsite@… added

comment:8 Changed 9 years ago by Jacob

Triage Stage: UnreviewedSomeday/Maybe

comment:9 Changed 8 years ago by mrts

milestone: post-1.0

Non-essential for 1.0.

comment:10 Changed 8 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:11 Changed 6 years ago by Łukasz Rekucki

Keywords: feature_request removed
Severity: normalNormal
Type: defectNew feature

comment:12 Changed 6 years ago by anonymous

I would not tie this kind of information to the Model. What would you say about the following syntax?

class PersonForm(forms.ModelForm):
    full_name = forms.CharField()

    class Meta:
        exclude = ('first_name', 'last_name',)
        aggregation = {
            'full_name': '%(last_name)s, %(first_name)s',
        }

There would be no 'full_name' key in PersonForm.cleaned_data, but 'first_name' and 'last_name'. Validation errors (like incompatibility with format string) would be raised for the full_name field.

comment:13 Changed 6 years ago by msiedlarek

Cc: msiedlarek added

Forgot to login. comment:12 is mine.

[edit]

Found django-developers thread. Nevermind.

Last edited 6 years ago by msiedlarek (previous) (diff)

comment:14 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:15 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:16 Changed 5 years ago by Alan Justino da Silva

Cc: Alan Justino da Silva added

comment:17 Changed 5 years ago by Simon Charette

Cc: charette.s@… added

comment:18 Changed 3 years ago by Jelko Arnds

Cc: j.arnds@… added

comment:19 Changed 3 years ago by Carlos Palol

Cc: carlos.palol@… added

comment:20 Changed 3 years ago by anonymous

UI/UX: set

comment:21 Changed 3 years ago by anonymous

UI/UX: unset

comment:22 Changed 3 years ago by loic84

I think this can be trivially implemented with a custom field and with the current public APIs.

Any objection to closing this ticket?

comment:23 Changed 3 years ago by Aymeric Augustin

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top