News for hackers. Stuff that matters.
Re:Show HN: Django Model Parsing with Python's AST module by natrius on Saturday October 13, 2012 @02:37PM (#4649272)
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.

Re:Show HN: Django Model Parsing with Python's AST module by fatiherikli on Saturday October 13, 2012 @02:44PM (#4649295)
It's true, but the _meta way is not convenient for my use case. I am parsing uploaded python script (django model).
Re:Show HN: Django Model Parsing with Python's AST module by natrius on Saturday October 13, 2012 @02:53PM (#4649326)
I don't understand how you can run your parser if you can't run arbitrary Python code.
Re:Show HN: Django Model Parsing with Python's AST module by mcantelon on Saturday October 13, 2012 @02:59PM (#4649350)
Running untrusted code someone has uploaded is risky.
Re:Show HN: Django Model Parsing with Python's AST module by natrius on Saturday October 13, 2012 @03:11PM (#4649386)
Oh, I get it. User-uploaded Django models. Makes sense.
Re:Show HN: Django Model Parsing with Python's AST module by DanielN on Saturday October 13, 2012 @02:03PM (#4649166)
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?
Re:Show HN: Django Model Parsing with Python's AST module by fatiherikli on Saturday October 13, 2012 @02:13PM (#4649189)
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.
Re:Show HN: Django Model Parsing with Python's AST module by __alexs on Saturday October 13, 2012 @02:15PM (#4649194)
Can you explain some more? That sounds like what the ORM Models already do.
Re:Show HN: Django Model Parsing with Python's AST module by mattdeboard on Saturday October 13, 2012 @02:17PM (#4649201)
manage.py sqlall ?
Re:Show HN: Django Model Parsing with Python's AST module by lmz on Saturday October 13, 2012 @02:31PM (#4649250)
doesn't that import the modules i.e. execute them?
Re:Show HN: Django Model Parsing with Python's AST module by natrius on Saturday October 13, 2012 @02:34PM (#4649259)
This project is a Python module. It has to be executed at some point. Presumably, you'd generate the SQL locally by running manage.py sqlall, then get the SQL to your database in the appropriate manner. That's the same process the eventual product of this module would require.
Re:Show HN: Django Model Parsing with Python's AST module by shabble on Saturday October 13, 2012 @11:03PM (#4650454)
That assumes your end goal is actually using the provided models in your application. It sounds like this is using them as pure data only.

I can think of a couple of reasons why you might want that, maybe if you wanted to create a relationship graph like django-extensions 'graph_models'[1], or build some sort of introspective API scaffold generator or something.

[1] https://github.com/django-extensions/django-extensions/blob/...

Re:Show HN: Django Model Parsing with Python's AST module by mattdeboard on Saturday October 13, 2012 @01:34PM (#4649096)
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