Django: nice and critical (article)
I am a django fan and I am using it for a while and very successful in a couple of projects. But reading this article fortunately makes me take a step back and rethink some of the things and be a little more critical with the blindness that sometime just sets in when you are into one topic.
Not that I completely agree with all the points, but it just lets me clear my view a bit. I.e. the template approach of Django is in my eyes a very good one, we (also as developers) don’t want all the power of python in the template, it would just get us into other problems, that other known languages have. And the extensibility of django templates is just very simple and not a reason for me to really complain about it.
Let me say up front I will use Django in my next project again and I think it’s great for quickly coming up to speed and getting things done and to be honest most things are about that. A while ago I developed a very DB intense application, that used a lot of difficult joins and I wouldn’t know if Django would have been the right choice for that. On the other hand I think that some customization would make me able to get all the good stuff Django provides and combine the needs with the luxury.
I actually wanted to list some problematic items that came along my way while working with Django:
- no support for aggregation in SQL, we did that all by hand or using triggers or view, which was a quite efficient solution in our case, I am not to unhappy with it
- some limitation in the model and SQL building sometimes step on your feet, i.e. creating a n:m relation creates a relational table that can not be adapted in any way, to store additional data in there, which is sometimes needed
- Extending the user model is a bit tricky by using the UserProfile approach and actually having two models for user data, we ran into this trap a couple of times. But a possible solution, which we haven’t tried yet but discussed and found to solve the problem was creating a view which provides all the user data as one model and read only from there, that will surely work perfectly and have the advantage that you can even provide additional data that the User and UserProfile models don’t provide. Just be careful to not blow up your DB :-).
- The I18N approach of Django is pretty easy to use, but it gets to it’s limits when it gets difficult. Translating strings that are made up of HTML chunks gets difficult.
Don’t see this post as a rant against Django, it’s not meant to be at all. I could probably make a much longer list of advantages.
Jacob Kaplan-Moss said,
June 14, 2007 at 5:39 pm
Thanks for the constructive criticism — critiques like yours always help us improve. In fact, I should point out that fixing the first two items on your list are pretty high priority right now. Finding the right syntax is tricky, but we’ve got smart people working on it.
User model extension is a bit harder. I’m not all that pleased with UserProfile (since I came up with it I’ve got nobody but myself to blame…) but it’s hard thinking of a better way. I’d be interested in reading more about the possible solution you outline here, though.
Julian said,
June 14, 2007 at 6:43 pm
Yeah, that there’s no support for aggregation is bad. I haven’t thought of views yet.
Question: How do you get the view back to a Django model? custom methods in the model.py? Or is it easier somehow?
Wolfram said,
June 15, 2007 at 9:45 am
Julian: what we did first was implementing just normal models in the models.py, but that always created the tables in the DB upon “syncdb” (which we deleted then and created views for). Actually I even wrote a patch for django where you can mark a model as “create_table=False” but the patch never made it in.
So we went another actually much better way, after discussing it a lot in the team. We simply did not create the models in models.py, which are used for syncdb but we create a file dbviews.py where we put the views’ models. This is very nice separation of code too.
The next step is writing the view itself, which we just did in pure SQL of course. I.e. if we have the model Forum and we want some specialized ForumActivity-view then we created a view “CREATE VIEW core_forumactivityview” (we are on mysql). We then fired that onto our DB and the model that matched it (make sure to use the same column names as the view does!!!) simply looks like this:
class ForumActiviy(models.Model):
….. all the fields
class Meta:
db_table = “core_forumactivityview”
now you can simply do
import project.core.dbviews
and they just look like models :-).
Depending on how you wrote the view you might even be able to update the data.
have fun
Wolfram said,
June 15, 2007 at 9:51 am
@Jacob:
actually we simply thought of creating a DB view which combines the auth_user table with the core_userprofile table, and have one model that works on this table, as i just described in the comment above. and that view should even be possible to update, so all the problems are solved
one just has to take care that you never use the userprofile model as a foreignkey but the user model always, then it should work fine and be consistent
wolfram
about:cmlenz said,
June 21, 2007 at 2:08 am
Logic in Templates…
Going through my referrer list, I found the blog post Django: nice and critical (article), which is in response to my own rant about Django, and among other things, contains the following: [] the template approach of Django is in…
Julian said,
June 22, 2007 at 2:11 pm
@Wolfram:
Cool, thanks for your response!
Wolfram said,
June 23, 2007 at 1:01 am
http://www.cmlenz.net/blog/2007/06/logic-in-templa.html has misunderstood my opinion about logic in templates, i said “we dont need all the power of python in the templates” and thats what I meant, the logic that django provides is a very good set of logic I want, reasonable and safe.
Christopher Lenz said,
June 27, 2007 at 9:00 pm
I don’t think that’s a misunderstanding, it’s simply disagreement
(Which is perfectly okay, of course)
sandrar said,
September 10, 2009 at 3:05 pm
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
angelina jolie said,
September 10, 2009 at 6:14 pm
I love your site.
Love design!!! I just came across your blog and wanted to say that I’ve really enjoyed browsing your blog posts. Sign: ndsam
Kelli Garner said,
September 26, 2009 at 11:28 pm
Thats very good to know… thanks
celebrity fuck you said,
August 24, 2010 at 8:28 pm
Sign: zdbrw Hello!!! nmxsc and 8966qnzbbpdycw and 3268 : Thanks. We look forward to hearing from you again and for your opinions on the world of work.
Yoko Auzat said,
January 5, 2012 at 9:31 am
The new Zune browser is surprisingly good, but not as good as the iPod’s. It works well, but isn’t as fast as Safari, and has a clunkier interface. If you occasionally plan on using the web browser that’s not an issue, but if you’re planning to browse the web alot from your PMP then the iPod’s larger screen and better browser may be important.
Cecil Vanderhoff said,
February 7, 2012 at 9:58 pm
naturally like your web-site however you need to take a look at the actual punctuational upon quite a few of your articles. Many of them are rife with spelling issues and I to find it pretty bothersome to tell the truth nevertheless I’ll definitely come again again.