Kwissle

My real-time quiz battle game Kwissle.com

Crosstips.org

My fun Crossword solver project. Crosstips.org & Krysstips.se

Kung Fu

Fujian White Crane Kung Fu

Photos

Photoalbum, both old and new.

Twitter

Follow me on Twitter

Contact me

My contact details and how to contact me.

 

KungFuPeople.com
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com


Mobile version of this page Mobile version of this page


 
PythonDjango

Musings about django.contrib.auth.models.User


27th of August 2010

Dawned on me that the Django auth user model that ships with Django is like the string built-in of a high level programming language. With the string built-in it's oh so tempting to add custom functionality to it like a fancy captialization method or some other function that automatically strips whitespace or what not. Yes, I'm looking at you Prototype for example.

By NOT doing that, and leaving it as it is, you automatically manage to Keep It Simple Stupid and your application code makes sense to the next developer who joins your project.

I'm not a smart programmer but I'm a smart developer in that I'm good at keeping things pure and simple. It means I can't show off any fancy generators, monads or metaclasses but it does mean that fellow coders who follow my steps can more quickly hit the ground running.

My colleagues and I now have more than ten Django projects that rely on, without overriding, the django.contrib.auth.models.User class and there has been many times where I've been tempted to use it as a base class or something instead but in retrospect I'm wholeheartedly happy I didn't. The benefit isn't technical; it's a matter of teamwork and holistic productivity.



Comment

Vincent Driessen - 28th August 2010  [«« Reply to this]
Have you ever extended the User object in another way, then? Without using subclasses? How did you do it? Did you make another model with a ForeignKey to User?

Or did you use User profiles?

Cheers,
Vincent
Peter Bengtsson - 28th August 2010   [«« Reply to this]
Yes, User profiles all the way!
Federico Cáceres - 29th August 2010   [«« Reply to this]
+1 to user profiles!
Ash Christopher - 1st September 2010  [«« Reply to this]
Instead of sub-classing, you can look at using mix-ins.
Peter Bengtsson - 1st September 2010   [«« Reply to this]
How is that any different? My point was that by leaving it as it is it becomes predictable when you go from project to project.
Chris - 7th June 2011  [«« Reply to this]
Perfect! Googled for this problem and I get your blog of all things. I was trying to access a user's profile photo in a comments template - the photo is stored in a custom model which references contrib.auth.models.User, and I had the option of doing something crazy with users, or adding 1 line of code. User Profiles is perfect.
 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.