Posts Tagged ‘Django’

Easy Ajax Forms with Fancybox

Note: The fancybox jQuery plugin can be found here. Last week we rolled out a new design for yipit, which I’m really excited about. It looks awesome. Sam Brown did an amazing job. In a few different places we decided to use modal forms that would submit via Ajax. I think technique provides great UX, […]

Optimized Django M2M “in” Queries

ManyToManyFields in Django have a big inefficiency when running a query to get objects that share a ManyToMany relation with another object. Consider these three models:

Django: Check If a Field has Changed

I got fed up with manually checking if a field has changed in the save method of Django models so I quickly wrote this snippet to generalize it: def has_changed(instance, field): if not return False old_value = instance.__class__._default_manager.\ filter([field] return not getattr(instance, field) == old_value Here’s how could be used: class Sneetch(models.Model): has_star = […]

Using Custom Django QuerySets

When I first started working with Django, I became frustrated that managers were not chainable. (If you don’t know what a Manager is you probably won’t find this post very useful. I recommend the DjangoBook for beginners.) Here’s a tutorial on a coding pattern our development team uses all the time on our PerformMatch product. […]