A models file might use a lot of class from the django.db.models module and importing each class lead to lengthy import line. That's might be one reason. The better reason might be that a lot of these class are named the same in django.forms and django.db.models. When you type models.CharField, you know you are working with a models field.
There is a balance to find between explicit and implicit, complexity, readability and purity at the price of practicality. I'm curious of what other people thinks of that. 2016-08-01 14:09 GMT+02:00 graeme <graeme.piete...@gmail.com>: > I have always imported models, and then: > > class Foo(models.Model): > bar = models.CharField(max_length=100) > > > which is what the examples in the django docs do - I copied it when I > started using Django and the habit stuck. > > It is a lot less verbose to do: > > from models import Model, CharField > > class Foo(Model): > bar =CharField(max_length=100) > > because each imported class is used many times in a typical models file. The > same apples to forms. > > On the other hand the generic views documentation tends to do things like: > > from django.views.generic.detail import DetailView > > > I have increasingly tended to do the same with forms, but not for models, > except for things like Q which would be verbose to do otherwise > > Which is better style (and why)? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/f644ac2f-098a-4bdb-a67e-d17e762a4ce7%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Cordialement, Coues Ludovic +336 148 743 42 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTaXMMWfhsdhUNRoS-SzKidFu5jo%2BExsexUnJXgROxYPbw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.