python - Django filter() returning object instead of contents -


brand new django excuse newbie question. cannot life of me google search return need.

first, imported these using inspectdb.

second, before providing the:

    def __unicode__(self):        return u'%s %s' % (self.id, self.cuisine) 

in models, every database showed looked bound objects versus actual data when looking in admin. assumed normal.

now i'm trying query database , show results. doing simple, code is:

def expand(request):     userid = userid.objects.filter(name__contains="test")     return render(request,'expand.html',{'userid':userid}) 

the return should test 1, test 2, instead get:

[<userid: userid object>, <userid: userid object>] 

tried userid, userid.name in template , both return object versus contents.

thanks, sorry i'm sure repeat question!

model:

class userid(models.model):     id = models.bigintegerfield(primary_key=true, db_column='id') # field name made lowercase.     name = models.textfield()     joindate = models.datefield(db_column='joindate') # field name made lowercase.     visits = models.integerfield(null=true, blank=true)     gender = models.textfield(blank=true)     address = models.textfield()     address2 = models.textfield(blank=true)     addresscity = models.textfield(db_column='addresscity') # field name made lowercase.     addressstate = models.textfield(db_column='addressstate') # field name made lowercase.     addresszip = models.integerfield(db_column='addresszip') # field name made lowercase.     rating = models.integerfield()     lastvisit = models.datefield(null=true, db_column='lastvisit', blank=true) # field name made lowercase.     topcuisine1 = models.integerfield(null=true, db_column='topcuisine1', blank=true) # field name made lowercase.     topcuisine2 = models.integerfield(null=true, db_column='topcuisine2', blank=true) # field name made lowercase.     topcuisine3 = models.integerfield(null=true, db_column='topcuisine3', blank=true) # field name made lowercase.     topcuisine4 = models.integerfield(null=true, db_column='topcuisine4', blank=true) # field name made lowercase.     topcuisine5 = models.integerfield(null=true, db_column='topcuisine5', blank=true) # field name made lowercase.     dealsparticipatedin = models.integerfield(db_column='dealsparticipatedin') # field name made lowercase.     privateoffersparticipatedin = models.integerfield(db_column='privateoffersparticipatedin') # field name made lowercase.     privateofferssent = models.integerfield(db_column='privateofferssent') # field name made lowercase.     toprestaurant1 = models.integerfield(db_column='toprestaurant1') # field name made lowercase.     toprestaurant2 = models.integerfield(db_column='toprestaurant2') # field name made lowercase.     toprestaurant3 = models.integerfield(db_column='toprestaurant3') # field name made lowercase.     dob = models.datefield(null=true, blank=true)     tipsrating = models.integerfield(null=true, db_column='tipsrating', blank=true) # field name made lowercase.     visitsweekday = models.integerfield(null=true, db_column='visitsweekday', blank=true) # field name made lowercase.     visitsweekend = models.integerfield(null=true, db_column='visitsweekend', blank=true) # field name made lowercase.     reviewrating = models.integerfield(null=true, db_column='reviewrating', blank=true) # field name made lowercase.     spendrating = models.integerfield(null=true, db_column='spendrating', blank=true) # field name made lowercase.     class meta:         db_table = 'userid' 

template:

<p>{{ userid }}</p> 

you need parse through object elements individually.

like this:

{% user in userid %}     {{user}} {% endfor %} 

--or--

{% user in userid %}     {{user.name}} {% endfor %} 

the __unicode__ attribute applied individual objects, , not queryset. hence issue.

make sure __unicode__ on userid model.

if want display name list, can alternatively do

def expand(request):     userid = userid.objects.filter(name__contains="test").values_list('name', flat=true)     return render(request,'expand.html',{'userid':", ".join(list(userid))}) 

and template just:

{{userid}} 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -