Skip to content
Learn Netverks

Lesson

Step 10/36 28% through track

classes-oop

Classes and OOP

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Classes and OOP: the syntax, APIs, and habits you need before advancing in Django.

Frameworks like Laravel are OOP-first—classes, visibility, and inheritance show up in every code review.

You will apply Classes and OOP in contexts like: SaaS dashboards, CMS-style products, internal tools, and APIs paired with React or mobile clients.

Write Python 3 in the editor and click Run on server—the dev runner executes your script; Django framework lessons also use local startproject for full MVT (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Every Django model is a Python class inheriting from models.Model. Class-based views (CBVs) encapsulate HTTP handling in classes. OOP is central—not optional.

Model classes

class Article(models.Model):
    title = models.CharField(max_length=200)
    def __str__(self):
        return self.title

__str__ improves admin and shell readability. Add methods for domain logic: def is_published(self): ...

Inheritance

  • Abstract base models share fields across apps
  • CBVs inherit from View, ListView, CreateView
  • Proxy models change behavior without new tables

Important interview questions and answers

  1. Q: FBV vs CBV?
    A: Function-based views are explicit; class-based views reuse generic patterns (list, detail, form)—pick clarity over cleverness.
  2. Q: What is Meta on a model?
    A: Inner class for options: ordering, verbose_name_plural, db_table.
  3. Q: __str__ vs __repr__?
    A: __str__ for humans (admin); __repr__ for developers debugging in shell.

Self-check

  1. What do all Django models inherit from?
  2. Why define __str__ on a model?

Interview prep

FBV vs CBV?

Function views are explicit; class-based views reuse generic patterns (ListView, CreateView)—pick clarity over abstraction for complex flows.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • self meaning?
  • Inheritance for models?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump