Model Meta Options

A snippet showing common Django model Meta options like ordering and db_table.


# models.py

from django.db import models

class Article(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique=True)
    published_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-published_at']
        db_table = 'blog_articles'
        verbose_name = "Blog Article"
        verbose_name_plural = "Blog Articles"
        unique_together = ('title', 'slug')

    def __str__(self):
        return self.title
  
Explanation:
  • ordering defines default sort order for queries (here newest first).
  • db_table lets you customize the actual database table name.
  • verbose_name and verbose_name_plural improve readability in Django Admin.
  • unique_together ensures that certain field combinations are unique across rows.
  • Meta options customize behavior without changing actual model fields or logic.
  • Category Models & ORM
  • Total Views 1191
  • Last Modified 23 December, 2025
  • Tags #models #meta #orm #config
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.