How to fix issue with passing class instances between methods in Python (Django context)?

I am practicing Object-Oriented Programming in Python (Django context). I have two classes: one represents a ProjectIdea, and another represents a ProjectIdeaBoard.

I want to:

  • Add (pin) a ProjectIdea instance to the board

  • Remove (unpin) a specific instance

  • Display all ideas with their details

However, I’m confused about how to properly pass and manage instances between methods.

Here is my simplified code:

class ProjectIdea:
    def __init__(self, title, description):
        self.title = title
        self.description = description


class ProjectIdeaBoard:
    def __init__(self, title):
        self.title = title
        self.ideas = []

    def pin(self, idea):
        self.ideas.append(idea)

    def unpin(self, idea):
        self.ideas.remove(idea)

    def count(self):
        return len(self.ideas)

My Questions:

  1. Is this the correct way to pass class instances between methods?

  2. What is the best way to safely remove an object (avoid errors if not found)?

  3. In Django, would this pattern be similar when working with models?


🔍 What I tried:

  • Using pop() instead of remove()

  • Creating instance inside constructor (didn’t work as expected)

    I want to understand the correct OOP approach for handling objects between classes, especially in real-world Django applications.

Вернуться на верх