Reputation: 1016
I have a many-to-many relationship between a link and a term in Django, but when trying to check if the relationship already exists between the link and term I'm getting an undefined variable on the method.
def create_models(my_term, link):
obj, created = WikifyProjectTerms.objects.get_or_create(term = my_term)
With my models as:
class WikifyProjectTerms(models.Model):
id = models.IntegerField(primary_key=True) # AutoField?
term = models.CharField(max_length=100)
class WikifyProjectLinks(models.Model):
id = models.IntegerField(primary_key=True) # AutoField?
links = models.CharField(max_length=100)
class WikifyProjectLinksTerms(models.Model):
id = models.IntegerField(primary_key=True) # AutoField?
links = models.ForeignKey(WikifyProjectLinks)
terms = models.ForeignKey('WikifyProjectTerms')
I have pasted the line from the django documentation https://docs.djangoproject.com/en/1.4/ref/models/querysets/#get-or-create (and tailored it) but Eclipse is insisting it does not exist, for any of my models. The update_or_create()
method doesn't exist either.
Any ideas will be appreciated!
This isn't a runtime error, this is Eclipse complaining:
Upvotes: 0
Views: 435
Reputation: 600041
Python, as I've had occasion to say once or twice before, is not Java.
One of things that makes it not-Java is that class attributes are defined dynamically. It is not always possible to determine what attributes an object has except at run-time.
Eclipse, or any other IDE that attempts to do static analysis of your code, is not reliable as a guide to what attributes do or do not exist on a class.
That's why many Python programmers prefer a simpler text editor - from vim to SublimeText - rather than an IDE. Don't forget, you have the Python shell which you can use to explore objects, using for example the dir()
command, which will show you what an object actually has rather than what an IDE thinks it has.
Upvotes: 2