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?
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.
- 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.
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.
app_label is used when you have models in a place in which django doesn't know to which app they belong.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With