elfs: (Default)
[personal profile] elfs

If you’ve created Django Application A, and then Django Application B, it is acceptable (and even sometimes necessary) for Application B to reference Application A.  The canonical example is Django contrib.auth; everyone references that beast.  It is not acceptable for you to go and edit Application A to reference Application B.  That is officially Doin’ It Wrong.

In a smarter world, you will never use a Django ManyToMany field.  You will create an individual class referencing both objects of the many-to-many relationship.  You will inevitably need more smarts than a mere two-column table, and a separate class, however small and insignificant, will provide both self-documentation and a chance to define the __unicode__() method for administration. Django is smart enough to hook up the relationships under the hood.

Unit testing is goddamned hard when your application is married to FacebookConnect.  A smarter relationship uses the SocialAuth layer, with additional proxies for information and posting handlers.  That way, not only can your application send updates to Facebook walls, but it can also update its activity on Twitter, and allow authentication via Google, and so on.  By using the SocialAuth layer, you can create a pseudo-layer that handles testing.  You’re still beholding to testing the SocialAuth stuff yourself.

If you’re using SocialAuth, push all of your user-related smarts into the UserProfile object, and always refer to it.  Build your UserProfile object to own the proxy to the user’s authenticated relationships with social media.  After login, leave the user alone!  Better yet, use middleware to attach the profile to the request object automagically if and when it’s present, and live with it.

This entry was automatically cross-posted from Elf's technical journal, ElfSternberg.com

Date: 2009-09-08 06:24 pm (UTC)
solarbird: (poor kitty!)
From: [personal profile] solarbird
WHAT

Date: 2009-09-08 06:25 pm (UTC)
solarbird: (pindar-most-unpleasant)
From: [personal profile] solarbird
Okay that's better. Jesus.

Date: 2009-09-08 06:36 pm (UTC)
From: [identity profile] elfs.livejournal.com
Sorry about that. I was working with a database of wine for testing and somehow a huge stream of it ended up in the clipboard for wordpress. It didn't show up on the wordpress site and I was "WTF?" when I saw it on LJ. I cleaned it up.

Date: 2009-09-08 06:42 pm (UTC)
solarbird: (Default)
From: [personal profile] solarbird
I totally thought (when I posted the WHAT) that it was some sort of spambot attaching itself to a new post of yours. At least it wasn't that. ^_^

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 5th, 2026 03:19 am
Powered by Dreamwidth Studios