does anyone use models with underscores in the name?

930 views
Skip to first unread message

Tim Graham

unread,
Oct 3, 2016, 12:30:44 PM10/3/16
to Django developers (Contributions to Django itself)
Ticket #27295 notes that the ORM doesn't work well with models that start with an underscore (e.g. _UsersGroup). I didn't check if the same problem exists with an underscore anywhere in the name, but I wanted to ask if anyone has seen model names that use underscores? If not, my proposal is to add a system check that prohibits an underscore in model names.

https://code.djangoproject.com/ticket/27295

ludovic coues

unread,
Oct 3, 2016, 12:34:27 PM10/3/16
to django-d...@googlegroups.com
I have seen that and so far I haven't found any issue if the
underscore is in the middle of the model name.
> --
> 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/44532a2c-69b7-45d7-8782-7b87eea09a20%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Constantine Covtushenko

unread,
Oct 4, 2016, 1:45:34 AM10/4/16
to django-d...@googlegroups.com
I am using such names in one of my project.
I found it very helpful for audit like fields: _cr_date and _cr_user

Regards,
Constantine C.

On Oct 3, 2016, at 19:30, Tim Graham <timog...@gmail.com> wrote:

Ticket #27295 notes that the ORM doesn't work well with models that start with an underscore (e.g. _UsersGroup). I didn't check if the same problem exists with an underscore anywhere in the name, but I wanted to ask if anyone has seen model names that use underscores? If not, my proposal is to add a system check that prohibits an underscore in model names.

https://code.djangoproject.com/ticket/27295

Tim Graham

unread,
Oct 4, 2016, 7:56:43 AM10/4/16
to Django developers (Contributions to Django itself)
To be clear, the proposed restriction is about starting model names with underscores, not model field names. I think you're usage refers to fields, but let me know if not.

Michal Petrucha

unread,
Oct 4, 2016, 8:11:06 AM10/4/16
to django-d...@googlegroups.com
We already flag the following as errors:

- field names, related names, and related query names ending with
underscores
- field names, related names, and related query names containing a
double underscore

I think it makes sense to also check for and flag as errors model
names starting or ending with underscores, or containing double
underscores, since those can lead to invalid field names. I think that
would be pretty consistent with the field name restrictions.

Cheers,

Michal
signature.asc

James Bennett

unread,
Oct 4, 2016, 8:19:36 AM10/4/16
to django-d...@googlegroups.com
I think I once implemented something that dynamically generated model classes at runtime and prefixed the class names with an underscore.

But I also didn't do much with those models other than set up tables for them and store/retrieve instances with very simple queries. Also, what I was doing was a very bad idea and abused the heck out of undocumented model internals, so I wouldn't be too upset if it turned out not to be reliable :)
Reply all
Reply to author
Forward
0 new messages