CITextField base class

167 views
Skip to first unread message

Sean Brant

unread,
Feb 7, 2017, 7:37:31 PM2/7/17
to Django developers (Contributions to Django itself)
I noticed the new postgres citext[1] field is a subclass of CharField. Wouldn't it be more correct to subclass TextField? Subclassing CharField means we need to add a max_length which is ignored in the db.


Adam Johnson

unread,
Feb 8, 2017, 5:32:22 AM2/8/17
to django-d...@googlegroups.com
Sounds legit, make a ticket

On 8 February 2017 at 00:37, Sean Brant <brant...@gmail.com> wrote:
I noticed the new postgres citext[1] field is a subclass of CharField. Wouldn't it be more correct to subclass TextField? Subclassing CharField means we need to add a max_length which is ignored in the db.


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/0e50eae1-8806-47fc-b223-9cac7152bf1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Adam

Mads Jensen

unread,
Feb 8, 2017, 6:00:23 AM2/8/17
to Django developers (Contributions to Django itself)


On Wednesday, February 8, 2017 at 11:32:22 AM UTC+1, Adam Johnson wrote:
Sounds legit, make a ticket

Shouldn't https://code.djangoproject.com/ticket/26610 just be reopened?
 
On 8 February 2017 at 00:37, Sean Brant <brant...@gmail.com> wrote:
I noticed the new postgres citext[1] field is a subclass of CharField. Wouldn't it be more correct to subclass TextField? Subclassing CharField means we need to add a max_length which is ignored in the db.


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.



--
Adam

Florian Apolloner

unread,
Feb 8, 2017, 7:32:17 AM2/8/17
to Django developers (Contributions to Django itself)


On Wednesday, February 8, 2017 at 12:00:23 PM UTC+1, Mads Jensen wrote:

Nope, since that ticket indeed got fixed. A bug in something that got committed usually also means new ticket.

Adam Johnson

unread,
Feb 8, 2017, 7:40:02 AM2/8/17
to django-d...@googlegroups.com
Pretty sure this is a new ticket since it's effectively a bug report

To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Adam

Tim Graham

unread,
Feb 8, 2017, 10:11:25 AM2/8/17
to Django developers (Contributions to Django itself)
Since that's a release blocker for a feature that hasn't been released yet, it's fine to reference/reopen the original ticket rather than create a new one. I've created a PR, https://github.com/django/django/pull/8034.


On Wednesday, February 8, 2017 at 7:40:02 AM UTC-5, Adam Johnson wrote:
Pretty sure this is a new ticket since it's effectively a bug report
On 8 February 2017 at 11:00, Mads Jensen <m...@inducks.org> wrote:


On Wednesday, February 8, 2017 at 11:32:22 AM UTC+1, Adam Johnson wrote:
Sounds legit, make a ticket

Shouldn't https://code.djangoproject.com/ticket/26610 just be reopened?
 
On 8 February 2017 at 00:37, Sean Brant <brant...@gmail.com> wrote:
I noticed the new postgres citext[1] field is a subclass of CharField. Wouldn't it be more correct to subclass TextField? Subclassing CharField means we need to add a max_length which is ignored in the db.


--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/0e50eae1-8806-47fc-b223-9cac7152bf1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.



--
Adam

Sean Brant

unread,
Feb 8, 2017, 10:40:56 AM2/8/17
to django-d...@googlegroups.com
Thanks Tim. I re-opened the ticket.

To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.

Jon Dufresne

unread,
Feb 8, 2017, 11:29:19 AM2/8/17
to django-d...@googlegroups.com
I believe this will also change the default form widget from <input type="text"> to <textarea>. Is that also desired? IME, I most often use citext with short text inputs, such as email.

To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.

Sean Brant

unread,
Feb 8, 2017, 11:41:45 AM2/8/17
to django-d...@googlegroups.com
Does it make sense to add a CICharField for these cases or you can just override the form/admin.

Jon Dufresne

unread,
Feb 8, 2017, 11:55:50 AM2/8/17
to django-d...@googlegroups.com
> Does it make sense to add a CICharField for these cases or you can just override the form/admin.

In a past Django developers discussion, Aymeric suggested building this functionality with a mixin so the citext type could apply to multiple DB fields which would then affect how the form field is rendered. Personally, I like this idea and believe it would provide the most flexibility such that a TextField, CharField, EmailField, etc. could all be backed by the citext type.

https://groups.google.com/d/msg/django-developers/SW7_qI81G58/i6aJVRnJBAAJ

From Aymeric in the previous thread:

---
I'm forseeing a small difficulty in terms of API. This is a behavior I'd like
to "mix in" to some fields but I can't say if that will be easy to implement.

The general ideas would be:

# A mixin

class CITextField(TextField):
    # ...

# Case-insensitive versions of some built-in Django default fields
# (if we consider that makes sense)

class CIEmailField(CITextField, EmailField):
    pass

# The possibility for users to make custom fields case insensitive

class CITagField(CITextField, TagField):
    pass
---

Tim Graham

unread,
Feb 8, 2017, 12:09:26 PM2/8/17
to Django developers (Contributions to Django itself)
I thought the mixin idea was good but everyone else (including Aymeric) reviewed the pull request and ignored your comment about that so I assumed no one else saw its merits. Considering a CITextField that uses CharField still has some usefulness as you mentioned, I'm in favor of CITextField not inheriting anything and requiring its use as a mixin -- unless there are some unforeseen problems with that.

Mads Jensen

unread,
Feb 9, 2017, 4:58:16 AM2/9/17
to Django developers (Contributions to Django itself)
I had the use case for shorter text strings in mind when I did the PR.

https://github.com/atombrella/django/commit/ae8fe50f34329cbc969c5ac5bd368efd5b42b177 <- would this be a better approach?

Tim Graham

unread,
Feb 9, 2017, 8:33:17 AM2/9/17
to Django developers (Contributions to Django itself)
That looks good to me.

Aymeric Augustin

unread,
Feb 9, 2017, 8:43:18 AM2/9/17
to django-d...@googlegroups.com
Hello,

I’m not a fan of having every project that needs case-insensitive fields declare:

class CICharField(CIText, CharField):
    pass

class CITextField(CIText, TextField):
    pass

class CIEmailField(CIText, EmailField):
    pass

Could Django take care of providing these classes? (And perhaps other useful ones?)

Best regards,

-- 
Aymeric.



-- 
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.

Adam Johnson

unread,
Feb 11, 2017, 5:38:56 AM2/11/17
to django-d...@googlegroups.com
I agree with Aymeric that the framework should contain any boilerplate rather than force projects to implement it themselves.

Hello,


-- 
Aymeric.



To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsub...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Adam
Reply all
Reply to author
Forward
0 new messages