[Django] #28347: Adding custom attributes to django model field

16 views
Skip to first unread message

Django

unread,
Jun 29, 2017, 3:59:21 PM6/29/17
to django-...@googlegroups.com
#28347: Adding custom attributes to django model field
-----------------------------------------+------------------------
Reporter: Tom Turner | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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]

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28347>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 29, 2017, 4:04:00 PM6/29/17
to django-...@googlegroups.com
#28347: Adding custom attributes to django model field
-------------------------------+--------------------------------------

Reporter: Tom Turner | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Tom Turner:

Old description:

> 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]
>
> If you accept this enhancement I am happy to write a patch, test and
> documentation. Please let me know.

New description:

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]

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

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28347#comment:1>

Django

unread,
Jun 29, 2017, 4:07:02 PM6/29/17
to django-...@googlegroups.com
#28347: Adding custom attributes to django model field
-------------------------------+--------------------------------------

Reporter: Tom Turner | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Old description:

> 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]
>
> If you accept this enhancement I am happy to write a patch, test and
> documentation. Please let me know.

New description:

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 say if you allow any attribute won't be good
as it could have 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.

--

Comment (by Tom Turner):

Replying to [ticket:28347 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]
>
> If you accept this enhancement I am happy to write a patch, test and
documentation. Please let me know.
>

--
Ticket URL: <https://code.djangoproject.com/ticket/28347#comment:2>

Django

unread,
Jun 29, 2017, 4:08:44 PM6/29/17
to django-...@googlegroups.com
#28347: Adding custom attributes to django model field
-------------------------------+--------------------------------------

Reporter: Tom Turner | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Tom Turner:

Old description:

> 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 say if you allow any attribute won't be good
> as it could have 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.

New description:

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28347#comment:3>

Django

unread,
Jun 29, 2017, 4:52:05 PM6/29/17
to django-...@googlegroups.com
#28347: Allow custom attributes for model fields
-------------------------------------+-------------------------------------

Reporter: Tom Turner | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => New feature
* component: Uncategorized => Database layer (models, ORM)


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/28347#comment:4>

Django

unread,
Jun 29, 2017, 5:19:22 PM6/29/17
to django-...@googlegroups.com
#28347: Allow custom attributes for model fields
-------------------------------------+-------------------------------------
Reporter: Tom Turner | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tom Turner):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28347#comment:5>

Django

unread,
Jun 29, 2017, 8:57:41 PM6/29/17
to django-...@googlegroups.com
#28347: Allow custom attributes for model fields
-------------------------------------+-------------------------------------
Reporter: Tom Turner | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Someday/Maybe


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/28347#comment:6>

Reply all
Reply to author
Forward
0 new messages