Skip to content

Conversation

sebbekarlsson
Copy link
Contributor

@sebbekarlsson sebbekarlsson commented Dec 8, 2018

So I had a problem where <select> lists had a fixed label.
For example when I had a ReferenceField(User) on my "EditTransactionForm" the list looked like this:

scrot

It was just a list of "User Object" , but I wanted it to display User.firstname in the list instead. This pull-> request makes that possible.

So, now I can do this:

class User(db.Document):
    name = db.StringField()


class Message(db.Document):
    recipent = db.SelectField(db.ReferenceField(User))

    def recipent_label_modifier(obj):
        return obj.title


user_items = [
    User(name=name).save()
    for name in ['Ronald', 'John']
]

Contacts(
    users=user_items 
).save()

ContactsForm = model_form(Contacts)
form = ContactsForm()

And achieve this:
scrot

@insspb
Copy link
Collaborator

insspb commented Jan 21, 2020

@sebbekarlsson I just diving into flask-mongoengine.
This is pretty old PR, but if you can rebase it to current source code and make some tests (pytest supported) it will be very helpful.

@sebbekarlsson
Copy link
Contributor Author

@insspb Okay cool! I will look into it soon.

@sebbekarlsson sebbekarlsson force-pushed the reference-field-callback branch 6 times, most recently from 66933be to a0a1ea5 Compare February 9, 2020 16:18
@sebbekarlsson sebbekarlsson changed the title adds the ability to change the label on every object in a queryset fo… Be able to change the label on every object in a queryset / select Feb 9, 2020
@sebbekarlsson sebbekarlsson force-pushed the reference-field-callback branch from 62a1224 to 31e60db Compare February 9, 2020 16:47
@sebbekarlsson
Copy link
Contributor Author

@insspb I have been rebasing, wrote some tests, made some modifications. Have a look

@insspb insspb force-pushed the reference-field-callback branch from 9d45435 to 6475cd5 Compare June 7, 2020 09:40
@insspb insspb added log:added Changelog mark label. Marks new added features. type: enhancement Enhancement update for old feature labels Jun 7, 2020
@insspb insspb changed the title Be able to change the label on every object in a queryset / select Added label_modifier option on ReferenceField conversion Jun 7, 2020
@insspb
Copy link
Collaborator

insspb commented Jun 7, 2020

@sebbekarlsson Thank you for contribution. Merged in master.

@insspb insspb merged commit c732d83 into MongoEngine:master Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
log:added Changelog mark label. Marks new added features. type: enhancement Enhancement update for old feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants