What is Django model Meta options?
Why Interviewers Ask This
This tests whether you can apply Django knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
Django model Meta class configures model-level behavior: class Article(models.Model): title = models.CharField(max_length=200) published_at = models.DateTimeField() author = models.ForeignKey(User, on_delete=models.CASCADE) view_count = models.IntegerField(default=0) class Meta: # Database ordering default: ordering = ["-published_at"] # Verbose names for admin: verbose_name = "Article" verbose_name_plural = "Articles" # Database table name: db_table = "blog_articles" # Database indexes: indexes = [ models.Index(fields=["published_at", "is_published"]), models.Index(fields=["author", "-published_at"], name="author_date_idx") ] # Unique constraints: unique_together = [["author", "title"]] # or: constraints = [ models.UniqueConstraint(fields=["author", "title"], name="unique_author_title"), models.CheckConstraint(check=models.Q(view_count__gte=0), name="non_negative_views") ] # Permissions: permissions = [("publish_article", "Can publish articles"), ("feature_article", "Can feature articles")] # Abstract base model: abstract = True # Proxy model: proxy = True # App label (for installed apps): app_label = "blog" # Default manager: default_manager_name = "published". Abstract models: share fields across models without creating a separate table. All subclasses get all abstract model fields. Proxy models: create a Python-level subclass (different behavior/methods/ordering) without a separate database table.
Pro Tip
This topic has Django-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.