Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Transitioning From PHP to Django
5 points by noelchurchill on May 5, 2008 | hide | past | favorite | 8 comments
If I’ve written a web application in PHP as a learning project, but at some point I may want to re-write using the Django framework, what would be the difficulties?

I feel like my primary concern would be getting the new Django app to play nice with the existing mysql database.

Has anyone had any experience doing this? Thanks.



I've worked with SQL for a long time, with a variety of implementations and front-ends. Django's object model hurt my head. I didn't get it. There's simply too much black magic.

e.g, how is:

  Entry.objects.filter(
    headline__startswith='What').exclude(
        pub_date__gte=datetime.now()).filter(
            pub_date__gte=datetime(2005, 1, 1))
(from http://www.djangoproject.com/documentation/db-api/)

easier than:

  SELECT * from Entry where headline like "What%" and pub_date...  wha?  see?  wtf is that chaining filter actually doing? 
my 2 cents: write your own DB access layer, fight the obscure black magic.

(nothing but quibbles with the templating engine, though)


the filter gives you a tangible "query" to work with so that you can continually add criteria as you build your query.

for example, i can say:

  grants = Grants.objects.filter(is_approved=True)
to get all of the Grants to an Organization, and then

  if not request.user.is_superuser:
      grants = grant.filter(sponsoring_trustee=request.user)
to filter out grants that only pertain to a certain user.

"grants" isnt evaluated (queried) until its iterated over or otherwise called (print, for example), so i can keep building what i want as i go without having several sql calls or managing building a query via string concatenation. personally, i've always found django's orm to feel natural.


The first thing I'd try is to reverse engineer the model from the database (this is something that django can do).

As long as your database design is somewhat decent you'll likely be ok. if not... well you might want to build a new model and migrate your data :)


How popular is the app? Does it work nicely now? Depending on your answers to those, do you really need to rewrite?


Right. That is a different question all together. I'm really more curious about Djangos ability to tap into an existing database. I've heard that RoR has a very difficult time doing this.

But to answer your question, there probably wouldn't be any need to rewrite my application. PHP is very adaptable and scalable and will probably continue to suit my needs.


Stick with PHP, Noel. :-)


But how do I resist the hype around all these frameworks?! haha jk.


check out manage.py's inspectdb command. it will make its best attempt (its been great w/ mysql) to introspect your schema and dump as a set of django models.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: