top | item 4648892

Show HN: Django Model Parsing with Python's AST module

23 points| fatiherikli | 13 years ago |github.com | reply

13 comments

order
[+] natrius|13 years ago|reply
Parsing the text of models isn't the best way to get information about them. The _meta attribute of a model provides tons of information about a model, its fields, and how to deal with its database representation.

Parsers are neat in general, so if you had fun with it, more power to you.

[+] fatiherikli|13 years ago|reply
It's true, but the _meta way is not convenient for my use case. I am parsing uploaded python script (django model).
[+] DanielN|13 years ago|reply
This seems really cool, but I'm having some trouble coming up with a use case for this. Why would I want to translate my django model to a dictionary?
[+] fatiherikli|13 years ago|reply
I will use it for generating database schema of uploaded django models. It's my use case. Because sandboxing in python is too hard, I can not execute uploaded python script.
[+] mattdeboard|13 years ago|reply
Neat. The AST module was a good way for me as a novice-intermediate programmer to get better acquainted with parsing. I have a small module that parses raw Solr-style querystrings into Haystack's SQ objects. Haven't touched it in months but it was a good learning exercise. https://github.com/mattdeboard/rawqs-sq