user1598865
user1598865

Reputation: 25

Django Foreign Key difficulty

I wrote the following model in Django, and wanted to define a foreign key to a class which is declared below the first class. Eclipse is showing an error. How to do it ?

class address_type(models.Model):
 address_type_desc = models.CharField(max_length=100)


class customer_address(models.Model):
 address_type_code = models.ForeignKey(address_type, related_name='type_of_address')

Upvotes: 0

Views: 148

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174728

You don't actually have an error, but you can use quotes:

class AddressType(models.Model):
 address_type_desc = models.CharField(max_length=100)


class CustomerAddress(models.Model):
 address_type_code = models.ForeignKey('AddressType', related_name='type_of_address')

I have also edited your class names to conform to the norm in Python. You should read pep-8, the official style guide for Python.

Upvotes: 2

Related Questions