Does Python have class prototypes (or forward declarations)?

Actually, all of the above are great observations about Python, but none of them will solve your problem.

Django needs to introspect stuff.

The right way to do what you want is the following:

class Car(models.Model):
    manufacturer = models.ForeignKey('Manufacturer')
    # ...

class Manufacturer(models.Model):
    # ...

Note the use of the class name as a string rather than the literal class reference. Django offers this alternative to deal with exactly the problem that Python doesn’t provide forward declarations.

This question reminds me of the classic support question that you should always ask any customer with an issue: “What are you really trying to do?”

Leave a Comment