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:
-
orderingdefines default sort order for queries (here newest first). -
db_tablelets you customize the actual database table name. -
verbose_nameandverbose_name_pluralimprove readability in Django Admin. -
unique_togetherensures 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
Previous snippet
Bulk Update with bulk_update()
Next snippet