Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composable verbose names #12

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

dokterbob
Copy link
Contributor

Allow using parent names to dynamically compose verbose names of subfields, like so:

    class IntegerEstimatedRange(CompositeField):
        minimum = models.DurationField(
            lambda n: _("%(parent_verbose_name)s minimum") % {
                "parent_verbose_name": n
            }
        )

    class Species(models.Model):
        height = IntegerEstimatedRange(verbose_name=_("plant height"))

See proposed documentation. Test added for it as well.

@bikeshedder
Copy link
Owner

Sorry for taking so long. I almost forgot about this issue.

In the example of this issue you've used a lambda expression but the code just relies on formatting via the % operator.

I guess passing a lambda as verbose_name didn't work?

@bikeshedder
Copy link
Owner

@dokterbob I just should have merged that back then. I got confused by the example provided in the issue. The code itself is fine. 😅

Thanks a lot and sorry for the delay.

@bikeshedder bikeshedder merged commit 7b39163 into bikeshedder:main Dec 10, 2024
1 check passed
@bikeshedder
Copy link
Owner

fyi. I just published version 2.0.1 which includes this change. Thanks a lot!

https://pypi.org/project/django-composite-field/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants