📜 ⬆️ ⬇️

What awaits us in Django 1.7

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.

image


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() # Default Manager entries = EntryManager() # Custom Manager b = Blog.objects.get(id=1) b.entry_set(manager='entries').all() 


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) #  Experiment.objects.filter(change__abs=27) #    # SELECT ... WHERE ABS("experiments"."change") = 27 


Other interesting changes


django.contrib.admin


django.contrib.auth


django.contrib.sites


E-mail


File upload


Forms


Internationalization


Management teams


Models


Requests and Answers

Utilities


This 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.

Source: https://habr.com/ru/post/224249/


All Articles