0

How convert u'[<Car: { surname :yass name : zazadz } >] in [<Car: { surname :yass name : zazadz } >].

So how convert unicode in django.db.models.query.QuerySet ?

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
YassVegas
  • 179
  • 6
  • 22
  • 1
    out of curiosity, how did you get to that point? – Pynchia Aug 12 '15 at 12:24
  • One form of my page contains this : . So I get this value in my view ( request.POST.get("rP","") ) but this value is unicode – YassVegas Aug 12 '15 at 12:26
  • 1
    OK, thank you. Must you keep that page as it is or can you change it? If so, what is the purpose of such field? I am trying to understand if there is a better way around this. – Pynchia Aug 12 '15 at 12:35
  • My page contains many querysets but these querysets are not all used ! My page contains 3 links, when I click on link I want pass to page specific to this link one qeueryset – YassVegas Aug 12 '15 at 12:39
  • BTW, the objects in the string/list have no id attribute, so if they refer to existing objects in the DB you would not know which ones they are. – Pynchia Aug 12 '15 at 12:40
  • I'd never hear of anyone trying to post a queryset from a page to the back-end. Normally it's the other way round. And the elements of the queryset are all disjoint, to be displayed/listed on the page – Pynchia Aug 12 '15 at 12:41
  • 2
    You can't output a queryset in a form field and pass it back through http post. HTML doesn't know anything about querysets. You'll need to work out some way of passing a simple value which indicates which queryset you want to use. – Daniel Roseman Aug 12 '15 at 12:42
  • Ok thank you.. I will find a solution ;) The problem is I don't want range all queryset in one page and hide/show some querysets depending on click of user... – YassVegas Aug 12 '15 at 12:46
  • initially I asked if you can change the page because it would be easier to pass the predicate that defines the queryset to the page (e.g. `{make='Ford', year='1990'}`) then in the view, parse the posted string into a dictionary you can use to execute a new query. – Pynchia Aug 12 '15 at 12:47
  • I try to don't use the database ^^ so I don't want execution of new query – YassVegas Aug 12 '15 at 13:09

1 Answers1

0

This is the function I wrote to convert unicode into string which i then process according to my need. _in_unicode is the parameter passed to this function, which takes an input of type unicode.

def unicode_to_string(_in_unicode):
return unicodedata.normalize('NFKD', _in_unicode).encode('ascii', 'ignore')

You will have to write a parser to process that string and then convert it into proper format for data processing.

P.S: If you are downvoting, please add comment for the reason.

Archit Singh
  • 109
  • 9