This post provides an overview of the innovations and features of the popular Django 1.7 framework among Python developers. The release is positioned by both the community and the main developers - as the most significant release since the release of Django 1.0.

Innovations in version 1.7
Termination of Python 2.6 support. Python version 2.7 and higher is now supported. Declared Python 3.4 support.
Added native support for
migrations directly to the framework itself. You can thank for this the author of the popular South battery -
Andrew Godwin .
')
The syncdb command is deprecated and will be removed in Django 1.9. Until then, syncdb is the alias of the migrate command, which provides both the execution of migrations and the old syncdb behavior.
Fixtures initial_data are no longer initialized by default for migrated applications. It is proposed to use the download fixtures at the level of the migrations themselves.
Application loading mechanism - has been fully refactored. As a result, you can opt out of models.py, which previously identified the application and was mandatory.
New methods of subclasses of
Field . The main feature is the obligatory deconstruct () method. Unfortunately, this is the fault of the inclusion of migrations in Django. If you inherit from standard fields and do not override the __init__ method, then you will not have to take care of this.
Now you can call
QuerySets directly from the manager:
class FoodQuerySet(models.QuerySet): def pizzas(self): return self.filter(kind='pizza') def vegetarian(self): return self.filter(vegetarian=True) class Food(models.Model): kind = models.CharField(max_length=50) vegetarian = models.BooleanField() objects = FoodQuerySet.as_manager() Food.objects.pizzas().vegetarian()
Ability to specify the necessary manager when using model binding:
class Blog(models.Model): pass class Entry(models.Model): blog = models.ForeignKey(Blog) objects = models.Manager()
The new system, for checking the project (System check), which, when launched, fixes problems and suggests what and how to fix it. For verification, use the new check command, which replaces the obsolete validate command.
New
Prefetch for advanced operations prefetch_related. Now you can configure prefetch using QuerySets.
Support for the current time zone in the admin panel, when working with the date widget. Previously used browser time zone. When the time difference in the browser and on the server - a visual hint is displayed.
The database cursor can now be used as a context manager, which is short for:
c = connection.cursor() try: c.execute(...) finally: c.close()
The ability to define your own
search types , for filtering when using ORM.
from django.db.models import IntegerField from django.db.models import Transform class AbsoluteValue(Transform): lookup_name = 'abs' def as_sql(self, qn, connection): lhs, params = qn.compile(self.lhs) return "ABS(%s)" % lhs, params IntegerField.register_lookup(AbsoluteValue)
Other interesting changes
django.contrib.admindjango.contrib.authdjango.contrib.sitesE-mailFile uploadForms- The textarea now includes the max_length attribute if max_length is defined in the model.
- Field.choices allows you to set the value for an empty value. Default "-------".
- In forms in the clean () method, it is no longer necessary to return self.cleaned_data.
- Now you can remove fields from the form by setting their name to None.
- The new method add_error () allows you to set errors for specific fields.
- Added the ability to set and display errors to constraints of the type unique, unique_for_date, and unique_together.
Internationalization- The django.middleware.locale.LocaleMiddleware.response_redirect_class attribute allows you to set up forwarding.
- LocaleMiddleware stores the user-selected language in _language. You can get access using the constant LANGUAGE_SESSION_KEY.
- The blocktrans tag removes the trimmed attribute. This option removes new line characters from beginning to end, combining them separated by a space. Which is convenient for generating locale files.
- Improved makemessages .
- The following language constants have been added: LANGUAGE_COOKIE_AGE, LANGUAGE_COOKIE_DOMAIN and LANGUAGE_COOKIE_PATH.
Management teams- Ability to disable color output in the console.
- Added the ability to dump data with primary keys during serialization.
- There is no need to specify the name of the cache table when using createcachetable. Now Django does it itself, taking into account the cache settings in the project settings.
- The runserver command has been improved. Now, with pyinotify installed, the reload speed is higher and consumes less battery on laptops. The server also reloads when using the compilemessages command. All requests for statics that were previously filtered are displayed in the console.
Models- New QuerySet.update_or_create () method.
- New Meta option default_permissions , which allows you to configure the create / modify / delete operations.
- OneToOneField detection when inheriting in abstract classes.
- Added the ability to use None as a query value when using iexact .
- The ability to use a single list in index_to together when specifying one set of fields (not a list in lists).
- Numeric fields are now checked depending on the database. Previously, it could lead to an error.
Requests and AnswersUtilitiesThis post is a free interpretation of official documentation in the development stage, and is for informational purposes only.
It includes the most interesting things from the point of view of the author of the post. For more detailed and detailed information, you can
go to the
documentation page.