Thursday, May 26, 2016

How to select undetermined field(s) in django model?

To all,

I am new to django, and learning to establish a site.

Here is my problem:
    I have got a databse and a table in mysql, and am using django to read the data from it.
    I got a pair of values [FIELD_NAME,VALUE] from the GET method of a html page. When the values passed to the searching function, I want to get the searching result.
    I knew how to do this in MySQLdb, but unable to achieve it in django model.
    In MySQLdb:
        cur.execute("SELECT COLUMN_A,COLUMN_B,COLUMN_C FROM mydatabase WHERE %s=%s",(filed_name,value))
    However, in django:
        results=mydatabase.objects.filter(filed_name=value)
    I got an error: Cannot resolve keyword 'filed1' into field. Choices are: Bla bla bla

   What should I do?

Bests.    
 
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bddb8755-33d2-4bb4-9769-3fb350a43ff0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment