1
Hello I am creating a project on Jango and performing a search for a Taginfo based on a tag that has foreignkey for Taginfo. I’m getting the following error on line 99 from view.
TypeError at /datasources/get/1/
int() argument must be a string or a number, not 'Taginfo'
Here is the model of the related classes.
class Tag(models.Model):
objects = GChartsManager()
idtag = models.IntegerField(db_column='idTAG', primary_key=True, editable=False) # Field name made lowercase.
desvio = models.FloatField(db_column='DEVIATION', blank=True, null=True) # Field name made lowercase.
tempo_max = models.IntegerField(db_column='TIME_MAX', blank=True, null=True) # Field name made lowercase.
conv_rate = models.IntegerField(db_column='CONV_RATE', blank=True, null=True) # Field name made lowercase.
taginfo_idtaginfo1 = models.ForeignKey('Taginfo', db_column='tagInfo_idTAGINFO') # Field name made lowercase.
datasource_idestacao_meteo = models.ForeignKey(Datasource, db_column='datasource_idDATASOURCE', blank=True, null=True) # Field name made lowercase.
def __unicode__(self):
return u'id = %s / id tagInfo => %s' % (self.idtag, self.taginfo_idtaginfo1)
class Meta:
managed = False
db_table = 'tag'
class Taginfo(models.Model):
objects = GChartsManager()
idtaginfo = models.IntegerField(db_column='idTAGINFO', primary_key=True, editable=False) # Field name made lowercase.
nome = models.CharField(db_column='NAME', max_length=45) # Field name made lowercase.
descricao = models.CharField(db_column='DESCRIPTION', max_length=255, blank=True) # Field name made lowercase.
def __unicode__(self):
return u'name = %s / description = %s' % (self.nome, self.descricao)
class Meta:
managed = False
db_table = 'taginfo'
Here is the view where the error occurs.
def datasource(request, datasource_id = 1):
# if there is
if Datasource.objects.filter(idestacao_meteo=datasource_id).count()>0 :
result = Datasource.objects.get(idestacao_meteo=datasource_id)
#if there is tags on this datasource
tags = None
tagsInfos = None
if Tag.objects.filter(datasource_idestacao_meteo = datasource_id).count>0:
tags = Tag.objects.filter(datasource_idestacao_meteo = datasource_id)
tagInfos = Taginfo.objects.filter()
for tag in tags:
idTaginfo = tag.taginfo_idtaginfo1
tagInfos = tagInfos.filter(idtaginfo = idTaginfo)
'''
tagInfo = {'' : 0}
for tag in tags:
tagInfo[tag.idtag] = Taginfo.objects.get(idtaginfo = tag.taginfo_idtaginfo1)
'''
else:
tags = None
tagsInfos = None
return render_to_response('Datasource/datasource.html',
#{'datasource' : result, 'tags' : tags}
{'datasource' : result, 'tags' : tags, 'tagInfos' : tagInfos}
)
else:
return render_to_response('Datasource/datasourceDoesNotExist.html',
{'datasource_id' : datasource_id }
)
I do not know pq this error occurs pq the both fields are int and one is Foreign key and the other a Primary key.
Thank you in advance.
What is the 99 line of the view?
– mgibsonbr
Line 99 -> tagInfos = tagInfos.filter(idtaginfo = idTaginfo)
– Nathan
That’s what I figured. In this case, see my answer, if you still have questions you can ask.
– mgibsonbr