Migrating Your App to Django


Posted

in

,

A few days ago I mentioned Changeset 384 which included a new command, django-admin.py inspectdb <dbname>. It has also been tweaked and improved since it was initially committed. The other day I tried it out on a simple database structure, but I decided to throw a more complex example at it.

I decided to take the final depot application from the excellent Agile Web Development with Rails book. Beta books rule by the way. I executed the SQL in rails-code/depot_final/db/create.sql from the the code tarball to set up the database structure. I then created a new project with django-admin startproject and edited settings/main.py to tell Django how to log in to my mysql database. After exporting the correct DJANGO_SETTINGS_MODULE I ran django-admin.py inspectdb depot_rails which gave me the following model:

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#     * Rearrange models' order
#     * Add primary_key=True to one field in each model.
# Feel free to rename the models, but don't rename 
# db_table values or field names.
#
# Also note: You'll have to insert the output of 
# 'django-admin.py sqlinitialdata [appname]'
# into your database.

from django.core import meta

class LineItem(meta.Model):
    db_table = 'line_items'
    fields = (
        meta.IntegerField('id'),
        meta.IntegerField('product_id'),
        meta.IntegerField('order_id'),
        meta.IntegerField('quantity'),
        meta.FloatField('unit_price'),
    )

class Order(meta.Model):
    db_table = 'orders'
    fields = (
        meta.IntegerField('id'),
        meta.CharField('name', maxlength=100),
        meta.CharField('email', maxlength=255),
        meta.TextField('address'),
        meta.CharField('pay_type', maxlength=10),
        meta.DateTimeField('shipped_at'),
    )

class Product(meta.Model):
    db_table = 'products'
    fields = (
        meta.IntegerField('id'),
        meta.CharField('title', maxlength=100),
        meta.TextField('description'),
        meta.CharField('image_url', maxlength=200),
        meta.FloatField('price'),
        meta.DateTimeField('date_available'),
    )

class User(meta.Model):
    db_table = 'users'
    fields = (
        meta.IntegerField('id'),
        meta.CharField('name', maxlength=100),
        meta.CharField('hashed_password', maxlength=40),
    )

Per the comment block at the top, you’re not home free yet, but at lot of tedious work has been done for you. This should definitely jumpstart the porting of existing applications to the Django platform.

Comments

99 responses to “Migrating Your App to Django”

  1. Bankruptcy Attorney New York City Avatar

    I think that may be a captivating aspect, it made me suppose a bit. Thank you for sparking my thinking cap. Every so often I am getting such a lot in a rut that I just feel like a record.

  2. Hip Hop Music Avatar

    Thank you for making the sincere effort to talk about this. I believe very sturdy approximately it and want to read more. If it’s OK, as you achieve extra intensive wisdom, may you mind including more articles similar to this one with more information? It might be extremely useful and useful for me and my friends.

  3. problem water Avatar

    Thank you for making the honest attempt to discuss this. I believe very robust about it and would like to read more. If it’s OK, as you gain extra extensive knowledge, may you mind adding extra articles similar to this one with more information? It could be extremely helpful and useful for me and my friends.

  4. buy propecia Avatar

    In my opinion, it is actual, I will take part in discussion. I know, that together we can come to a right answer.

  5. Bankruptcy Attorney New York City Avatar

    I image this could be numerous upon the written content? in spite of this I still imagine that it is usually suitable for nearly any form of topic subject matter, as a result of it would incessantly be pleasant to determine a heat and pleasant face or maybe pay attention a voice when preliminary landing.

  6. halo reach ranks Avatar

    I think that is a fascinating aspect, it made me think a bit. Thanks for sparking my pondering cap. On occasion I get such a lot in a rut that I simply really feel like a record.

  7. lanyards Avatar

    Thanks for making the trustworthy strive to give an explanation for this. I think very robust approximately it and wish to be told more. If it’s OK, as you attain more in depth wisdom, might you mind adding more posts similar to this one with additional information? It will be extremely useful and useful for me and my colleagues.

  8. Griffins cigars Avatar

    Good issues?I’d observe that as somebody who in point of fact doesn’t write on blogs so much (if truth be told, this may be my first put up), I don’t assume the term ‘lurker’ is very turning into to a non-posting reader. It’s no longer your fault in the slightest degree , but perhaps the blogosphere may come up with a greater, non-creepy identify for the 90% folks that enjoy reading the content material .

  9. electronic cigarette nicotine Avatar

    I am speechless. This is a excellent weblog and really enticing too. Great work! That’s no longer in reality much coming from an amateur publisher like me, but it’s all I may just say after diving into your posts. Great grammar and vocabulary. Not like different blogs. You actually realize what you?re speaking about too. Such a lot that you made me want to explore more. Your weblog has grow to be a stepping stone for me, my friend.

  10. acai berry review Avatar

    We meet many people everyday in our life. We all struggle everyday try to be someone that good to other people life too. We need to appreciate all the people that we met everyday in our life.

  11. Jeremiah Engwall Avatar

    ample log you occupy

  12. wholesale napapijri Avatar

    Thanks for making the trustworthy attempt to explain this. I think very robust approximately it and want to be informed more. If it’s OK, as you attain extra in depth wisdom, may you thoughts adding extra posts very similar to this one with additional info? It would be extremely useful and helpful for me and my colleagues.

  13. NYC Movers Avatar

    City move can be and should be an easy process. With Manhattan Movers NYC it start with call to our office! No hidden costs, no surprices! Call us. We serve Manhattan, Brooklyn, Queens – all NYC. Manhattan Movers NYC, 553 Broome St, New York, NY 10013, (212)300-6628

  14. Consumer Wealth System Avatar

    I realy appreciate you guys taking the time to update these sites because they realy help me before i do anything to hastey.

  15. affordable health insurance houston Avatar

    We meet many people everyday in our life. We all struggle everyday try to be someone that good to other people life too. We need to appreciate all the people that we met everyday in our life.

  16. cochecitos para bebes Avatar

    These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post, writing is simply great, thank you for the post

  17. New Zealand QROPS Avatar

    I picture this may well be various upon the written content material? however I still imagine that it may be suitable for virtually any form of subject material, as a result of it would ceaselessly be fulfilling to determine a heat and pleasant face or possibly listen a voice when initial landing.

  18. chauvet lights Avatar

    I admire the valuable information you be offering on your articles. I will bookmark your blog and feature my kids test up here generally. I’m relatively positive they’re going to be informed plenty of new stuff here than any one else!

  19. Laurie Dolezal Avatar

    wow, great site, will be returning for much further reading to gain more info on this subject. Thanks – keep up the great work!

  20. mazda radio Avatar

    I like the precious data you offer for your articles. I will be able to bookmark your weblog and feature my kids check up here generally. I am moderately sure they’ll learn a whole lot of new stuff here than any one else!

  21. Reseguiden Avatar

    i’ve visited this cool site a couple of times now and i have to tell you that i find it quite good actually. continue doing what you’re doing! 😉

  22. how to use vigrx plus Avatar

    Just right points?I might notice that as someone who truly doesn’t write on blogs a lot (in truth, this can be my first submit), I don’t think the term ‘lurker’ is very turning into to a non-posting reader. It’s now not your fault the least bit , however most likely the blogosphere may get a hold of a better, non-creepy name for the 90% of us that enjoy reading the content material .

  23. Natural Weight Loss Pills Avatar

    I just stumbled across your website from a friend’s digg profile. Bless him. Websites like yours are really rare in a webspace full of crap and spam.

  24. carpet cleaning San Diego Avatar

    I like this information and it has given me some sort of desire to have success for some reason, so thanks. Furthermore I’m definitely considering blogging these facts in my own blog!

  25. Frauen kennenlernen Avatar

    I like this information and it has given me some sort of desire to have success for some reason, so thanks. Furthermore I’m definitely considering blogging these facts in my own blog!

  26. blackberry 9700 Avatar

    I realy appreciate you guys taking the time to update these sites because they realy help me before i do anything to hastey.

  27. lanyards Avatar

    Abnormal this put up is totaly unrelated to what I was looking out google for, but it surely used to be listed at the first page. I guess your doing something proper if Google likes you sufficient to place you at the first web page of a non related search.

  28. my blog Avatar

    Strange this publish is totaly unrelated to what I was searching google for, but it used to be indexed on the first page. I guess your doing something right if Google likes you adequate to position you on the first page of a non similar search.

  29. Eve Provosty Avatar

    wow, great blog, will be returning for much further reading to gain more info on this subject. Thanks – keep up the great work!

  30. Elvis Presley Avatar

    I’m happy I found this blog, I couldnt discover any info on this subject matter prior to. I also run a site and if you want to ever serious in a little bit of guest writing for me if possible feel free to let me know, i’m always look for people to check out my site. Please stop by and leave a comment sometime!

  31. Pioneer vsx-1020-k review Avatar

    Just right issues?I might be aware that as any individual who actually doesn’t write on blogs much (in reality, this can be my first publish), I don’t suppose the time period ‘lurker’ could be very becoming to a non-posting reader. It’s now not your fault in the slightest degree , but perhaps the blogosphere may get a hold of a greater, non-creepy title for the 90% folks that experience studying the content .

  32. club flyers Avatar

    Club flyers printing are great for advertising special events, and grand openings. Modern color flyer printing technology allows producing these flyers at a minimal cost, making them affordable for everyday use.

  33. Car Hire Malaga Airport Avatar

    You can tally me in for a Digg. Thanks for posting this on your web site!

  34. Paketresorna Avatar

    keep up the nice work on the site. I love it. Could use some more frequent updates, but i’m sure you got more or better things to do like we all do. =p

  35. plancher flottant Avatar

    I actually love how it is easy on my eyes and also the information are well written. I am wondering how I can be notified whenever a new post has been made. I have subscribed to your rss feed which ought to do the trick!

  36. mobile phone zapper Avatar

    I picture this may well be various upon the written content material? nevertheless I nonetheless believe that it can be suitable for nearly any form of subject subject material, as a result of it might often be pleasant to resolve a heat and pleasant face or perhaps hear a voice whilst initial landing.

  37. As the summer goes, winter comes.You should have some shoes in store. Based on this point, the Tory Burch sale Shoes is developing faster and faster. More and more people do online shopping.With so many shoes in it, now I advise you getting a pair of…

    Welcome to http://www.cheaptoryburchshop.com. Good news for ballet fans – an update on the classic Tory Burch flip flop and tory burch slipper! They are fit for everyday wearing,comfortable and goodlooking are the advantages.Tory Burch sale is a brand which d…

  38. cheap tory burch shoes …

    Saletoryubrchon.com provide good quality and best price for cheap tory burch shoes products, there offer tory burch boots,tory burch sandals,tory burch flats,tory burch handbangs sale, tory burch wallets for free shipping. …

  39. signs Avatar

    actually liked the article you wrote . it really is not that simple to find even remotely good stuff toactually read (you know READ! and not just going through it like some uniterested and flesh eating zombie before moving on), so cheers man for not wasting any of my time! :p

  40. Budapest Reseguide Avatar

    i have begun to visit this blog a few times now and i have to tell you that i find it quite good actually. keep it up! :p

  41. vigrx plus Avatar

    I’ve been reading your entries all through my morning break, and I will have to admit the whole article has been very enlightening and really well written. I assumed I would let you recognise that for a few reason this blog does now not view smartly in Web Explorer 8. I wish Microsoft may forestall converting their software. I’ve a question for you. Would you mind replacing weblog roll hyperlinks? That would be truly neat!

  42. Resorna Avatar

    actually like what that you have written actually. it really is not that simple to find even remotely good text toactually read (you know READ and not just going through it like some zombie before going to yet another post to just ignore), so cheers man for not wasting my time on the god forsaken internet. 😉

  43. Jere Halgas Avatar

    Thank you for this intresting article. :-)uglas Potters

  44. Carroll B. Merriman Avatar

    Dude, I think there is a mistake in the first paragraph, but I have to say very interesting article. Thanks, ley Tusa

  45. Carroll B. Merriman Avatar

    Dude, great article. Can you give me your email address. There is something I would like to ask you. Thanks ryanna Jarrett

  46. Andrew A. Sailer Avatar

    Dude, I think there is a mistake in the first paragraph, but I have to say very interesting article. Thanks, cqui Torelli

  47. web hosting india Avatar

    I have been studying your entries all over my morning break, and I will have to admit the entire article has been very enlightening and very well written. I assumed I would assist you to recognise that for a few reason this blog does now not view well in Web Explorer 8. I wish Microsoft could prevent changing their software. I’ve a query for you. Could you thoughts exchanging weblog roll hyperlinks? That may be in reality neat!

  48. Jaxasiasiaf Avatar

    Directory of restaurants organized by states Panda Express

  49. Quinn Hendrik Avatar

    I couldn’t have asked for a more rewarding blog. You are there to give excellent tips, going straight to the point for straightforward understanding of your subscribers. You’re undeniably a terrific professional in this subject. Thanks a lot for remaining there guys like me.