Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the standard docstring for a django model metaclass?

Models in django can come with a meta class like so:

class Address(models.Model):
    """Address model."""

    class Meta:
        """Meta McMetaface."""

        verbose_name = "Address"
        verbose_name_plural = "Addresses"

    address_line = models.CharField(max_length=256)
    postcode = models.CharField(max_length=10)

    def __str__(self):
        """Return address without post code."""
        return self.address_line

My metaclass is whimsical at best. Does Python or Django have a standard text for meta classes?

like image 433
AncientSwordRage Avatar asked Jul 26 '16 23:07

AncientSwordRage


People also ask

What is Meta class in Django?

Model Meta is basically the inner class of your model class. Model Meta is basically used to change the behavior of your model fields like changing order options,verbose_name, and a lot of other options. It's completely optional to add a Meta class to your model.

What is the standard Python docstring format?

- reST. Nowadays, the probably more prevalent format is the reStructuredText (reST) format that is used by Sphinx to generate documentation. Note: it is used by default in JetBrains PyCharm (type triple quotes after defining a method and hit enter). It is also used by default as output format in Pyment.

What is docstring in Django?

Python documentation string or commonly known as docstring, is a string literal, and it is used in the class, module, function, or method definition. Docstrings are accessible from the doc attribute (__doc__) for any of the Python objects and also with the built-in help() function.

What is App_label in Django?

app_label is used when you have models in a place in which django doesn't know to which app they belong.


1 Answers

There's no point in writing a docstring for Meta. It's a standard name that every model defines, and means the same thing in every model. Just don't write a docstring.

like image 108
Ned Batchelder Avatar answered Nov 15 '22 04:11

Ned Batchelder