Denis,

Please pardon a possible repeat message, but my previous message did
not show up in the generateds-users mailbox.

By the way, I've started working on loading instance data into a
Django database.  So far, I've been able to generate the models for
a sample XML schema, and then do:

    $ python manage.py makemigrations myapp
    $ python manage.py migrate

In order to do the above, I had to modify the django generator so
that it adds:

    on_delete=models.CASCADE,

I'm not sure why.  Am I using a different version of django?  My
version is django 2.0.5.

Also, I had to change the line generated in admin.py that reads:

    from models import \

to this:

    from .models import \
    
I believe that is because I'm using Python 3.6.6.  So, I'll need to
see about making that work with both Python 2.7 and 3.6.  Perhaps,
it's because I generated the project and app using Python 3.6.6?

My next step is to design and investigate the use of a method in the
classes generated by generateDS.py (let's call it exportDjango) to
capture XML instance data and load it into a django DB.  I still
have not gotten far enough to know whether doing that is feasible.

But, as Ringo Starr told us:

   "Got to pay your dues if you wanna sing the blues,
   And you know it don't come easy."

More later.

Dave

In and earlier message, dave wrote:

Denis,

> I'm using generateDS to create Django models from xml schemas. It's great.
> I even modified some code to generate SQLAlchemy models.

Cool.  Do you think that your modifications could be added to the
generateDS distribution?  Would you be willing to contribute them?
If so, I'd be willing to do a little clean-up work if needed.

> But I think the next step could be loading XML instance data into generated
> models. Did you think about this case?

Yes, I think that would be a valuable enhancement.  And, yes, I've
thought about it.  Of course, just thinking does not get us there;
I'd have to *do* something.

In the meantime, here are a few thoughts:

It might make sense to add support for loading instance data into a
Django model as another form of export.  generateDS already has
three of those.  From the help/usage message:

    --export=<export-list>   Specifies export functions to be generated.
                             Value is a whitespace separated list of
                             any of the following:
                                 write -- write XML to file
                                 literal -- write out python code
                                 etree -- build element tree (can serialize
                                     to XML)
                             Example: "write etree"
                             Default: "write"

There is a corresponding function in the `generateDS.py` module for
each of these: `generateExportFn`, `generateToEtree`, and
`generateExportLiteralFn`.  I suppose that we could consider adding
`generateExportDjangoFn` (or something like that), which would
generate exportDjango.  And, while working on that, it might be a
good idea to change `generateExportLiteralFn` to
`generateExportJSONFn` (or maybe create a new function to do that).
And, since you are apparently interested in the SQLAlchemy ORM,
perhaps we also have to consider `generateExportSQLAlchemy`.  Whew!

Effectively, we would be implementing a new function
(`generateExportDjangoFn`) that would generate a new method in each
class generated for each XML element type.  And, that new method
would (like the other export methods) would perform a tree walk of
the element type classes and while doing so would insert instance
data into the Django model.

Assumptions and cautions:

- The model (definition) is one that has been generated by
  generateDS.

- The model definition) was generated by the same XML schema that
  was used to generate the module containing the exportDjango
  methods used to populate it.  Perhaps we even need to implement a
  way to verify this (possibly using an shasum somehow?).

Requirements:

- There is a way to give each export method (say, `exportDjango`)
  a target, e.g. a Django database (and other info).

- We have to enable the export process to run within the Django
  environment.  Right?  Is that possible?  Need to check.  Run
  inside the Django `dbshell`?

It's be awhile since I've used Django, so I suppose I should
consider this as an opportunity to relearn what I've forgotten and
what I have yet to learn.

By the way, just recently I ran across the term ETL (extract
transform load, see https://en.wikipedia.org/wiki/Extract,_transform,_load),
although I believe that it's a rather old term.  It seems that we
should be trying to think of generateDS as a possible part of an ETL
tool chain.  And, related to ETL, I found notes about extracting
*text* documents and storing them in a database, and while doing so,
also using some of the Python data science tools (e.g.
scikit-learn) to help make an intelligent search capability.  That
sounds cool.  Perhaps thinking about ETL and intelligent search will
help motivate me.

Give me a little time to think about it and to try to get myself
motivated.

More later.

Dave

On Fri, Jun 29, 2018 at 08:57:33AM +0300, jabber wrote:
> Hello Dave,
> 
> I'm using generateDS to create Django models from xml schemas. It's great.
> I even modified some code to generate SQLAlchemy models.
> But I think the next step could be loading XML instance data into generated
> models. Did you think about this case?
> 
> Thank you.
> Denis

> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot

> _______________________________________________
> generateds-users mailing list
> generateds-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/generateds-users


-- 

Dave Kuhlman
http://www.davekuhlman.org

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to