On Sat, Feb 21, 2009 at 5:48 PM, Andrew Godwin <and...@aeracode.org> wrote:
> > Heh, as I expected. > > So, when I first started on South, I initially tried introspecting the > various fields to drag their parameters out of wherever they had been > saved to - for example, max_length in a field goes to self.max_length. > > Then, you have the special cases for Django core fields. For example, > Decimal field has self.max_digits, and self.decimal_places. Writing lots > of special cases is kind of ick, but still possible. > > The real problem is custom fields, which both me and the other Andy > have. You don't know where their arguments go, and so, without putting > the impetus on the field-writer to provide a "this is how i waz called" > function that produces the correct incantation, we're kind of stuck when > it comes to detecting how to instantiate the field so we can use it > (first to make it do database work for us, and now because, like > Migratory, we want to expose the ORM inside migrations). > > Thus, it was decided to just parse the models.py file and drag the field > definitions out of it. Up until now, this has been done using inspect, > some regexes and continuous applications of eval() (until it passes). > This does, contrary to what we expected, work reasonably well, but > there's still some cases where it doesn't quite work (there's at least > three South bugs open because of the models.py parser) and so it's > having a more robust rewrite. > > It also means less work when more built-in Django fields appear > (GeoDjango would be a previous example of that, I guess.) > > Pickling is the other option, but it's a) not editable by people - and > migrations are often edited by them and b) not always available (due to > the inherent security flaws it has). > > Hope that makes it somewhat clear... > > Andrew > > > Alex Gaynor wrote: > > > > I'm interested in your need to parse the file directly, can you > > elaborate on that? > > > > Alex > > > > -- > > "I disapprove of what you say, but I will defend to the death your > > right to say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > > > > > > > > Ok, why not look at at the fields __dict__, I realize that it's not perfect since you could assign a computed value to an attribute, but perhaps some combination of that, filtering out items based on what you know are computed values(such as "rel") and introspecting the __init__ method with the inspect module could be used to get the information without resorting to parsing the file. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---