If meta classes in models are inherited from an object

It seems pretty arbitrary to write models something like this:

from django.db import models

class Foo(models.Model):
     name = models.CharField(max_length=100, null=False)

     class Meta:
         ordering = ("name")

Is there any reason class Meta:, not class Meta(object):? Is there any reason not to inherit explicitly from object?

+4
source share
2 answers

Like Stephen, note that since version 2.0, Django only supports Python 3; in this version of Python there is no need to inherit from the object, all classes are automatically "new style".

+1
source

Inheritance with objectdoes not matter. Template:

class Foo():
    class Meta:
       attribute = 'This is Interesting'

First of all, it’s easier to do than later code:

if Foo.Meta.attribute == 'How Boring':
    ....

Meta, Meta, , .

+1

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


All Articles