Opened 8 years ago

Last modified 8 years ago

#28347 new New feature

Allow custom attributes for model fields

Reported by: Tom Turner Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no
Pull Requests:How to create a pull request

Description (last modified by Tom Turner)

I want to add a custom attributes to a Django model field

name = models.CharField(max_length=255, data_merge=True)

I want to do this so i can loop round my fields and see if this field is set.

        for field in Project._meta.get_fields(include_parents=False, include_hidden=False):
            if field.extra_info.data_merge:
                   // do something here

I haven't been the first to ask for this see https://stackoverflow.com/questions/20679057/adding-custom-attributes-to-django-model-field

I understand that you might not won't any attribute won't be good as it could hide error. So one could do

name = models.CharField(max_length=255, meta_data={'data_merge':True})

If you accept this enhancement I am happy to write a patch, test and documentation. Please let me know.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • Unknown. The Someday/Maybe triage stage is used to keep track of high-level ideas or long term feature requests.

    It could be an issue that's blocked until a future version of Django (if so, Keywords will contain that version number). It could also be an enhancement request that we might consider adding someday to the framework if an excellent patch is submitted.

    If you're interested in contributing to the issue, raising your ideas on the Django Forum would be a great place to start.

Change History (6)

comment:1 by Tom Turner, 8 years ago

Description: modified (diff)

in reply to:  description comment:2 by Tom Turner, 8 years ago

Description: modified (diff)
Last edited 8 years ago by Tom Turner (previous) (diff)

comment:3 by Tom Turner, 8 years ago

Description: modified (diff)

comment:4 by Tim Graham, 8 years ago

Component: UncategorizedDatabase layer (models, ORM)
Summary: Adding custom attributes to django model fieldAllow custom attributes for model fields
Type: UncategorizedNew feature

What's the problem with writing a custom model field? My inclination is that allowing a dictionary of arbitrary options isn't a good design as it can be used and abused for any purpose and different Django applications might choose conflicting key names for different purposes.

comment:5 by Tom Turner, 8 years ago

I would have to write a custom field for all the different types of models that i use CharField, FloatField, ForeignKey, PositiveSmallIntegerField, IntegerField etc

comment:6 by Tim Graham, 8 years ago

Triage Stage: UnreviewedSomeday/Maybe

Please write to the DevelopersMailingList to see if there's consensus. Perhaps someone will have an idea about a more elegant approach.

Note: See TracTickets for help on using tickets.
Back to Top