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 instance.pk:
        return False
    old_value = instance.__class__._default_manager.\
             filter(pk=instance.pk).values(field).get()[field]
    return not getattr(instance, field) == old_value

Here’s how could be used:

class Sneetch(models.Model):
    has_star = models.BooleanField(default=False)
    succumbs_to_peer_pressure = models.BooleanField(default=False)

    def save(self, *args, **kwargs):
        if has_changed(self, 'has_star'):
            self.succumbs_to_peer_pressure = True
        super(Sneetch, self).save(*args, **kwargs)

Let me know if you improve it…

3 Ways To Guarantee I’ll Never Work For You

It’s not easy to find developer in New York. At the moment, this city does not have enough technical talent. I think this will change quickly as NYU leads a charge for universities to become more involved in the startup scene, but as things stand, there are lot of business guys, a lot of ideas, and not a lot of people who code. Almost every New York Tech Meetup presentation ends with “By the way, we’re looking for (Ruby|Python) developers, so contact us if you’re interested.”

Most companies put themselves at an even greater disadvantage in recruiting by writing awful job listings. If you include any of these 3 things, I promise to not be interested:

Ambiguous Pricing Sells Businesses Short

Last night I went to grab some late night pizza with my friend Matt. (It was technically May 6th, so I no longer felt obligated to eat tacos.) There was no posted menu, so when we got the front of the line, I decided to ask about the price difference between a plain slice and a slice with toppings. I was told that both were $3.50, so I ordered a slice of sausage. Matt got a slice with pepperoni and mushroom, and he was also charged $3.50. The guy behind us got a slice with sausage and pepperoni; he was charged $5.00. If I could remember which pizza place we were at, I wouldn’t go back.

There’s a delicious pasta place on 22nd and 3rd called lamarca. There are two entrances: one into a cheese shop and one into a sit down restaurant. The first time I went, my group walked in and tried to figure out where we should be going. There was no menu in the cheese shop, so we decided on the restaurant. The food was great, but the pasta lunch ended up costing us each around $15, which was surprising since we had heard it was very inexpensive. Since then I’ve learned they have a 3 tiered pricing scheme:

  • If you order form a waitress, it costs about $15 and you get a roll, a small side salad, a fancy bowl and a metal fork.
  • If you order from the cheese shop and sit down in the restaurant, it costs about $8, but you get a different bowl and a plastic fork
  • If you order to-go from the cheese shop, it costs about $7; no bowl, but you still get the fork

I’ve been back to lamarca because the food is great and affordable (now that I’m on the inside), but I never feel good about giving them my money. I’d go there a lot more often if they had been straightforward with their pricing the first time I went.

I hate when businesses don’t make pricing information available to their customers and then try to take advantage of the fact that their customers and uninformed. While these tactics do promote price discrimination and, therefore, short term profits, they are myopic and bad for business.

When Ben and I ran Wash-U-Wash, we  prided ourselves on customer satisfaction. One year many of our customers gave us more pounds of laundry then they had paid for. While most customers never asked us about the status of their account, we were also irresponsible about reaching out to our customers when they went over. Contractually, we had the right to collect a significant amount of money; however, we felt that we weren’t transparent enough about account balances. We decided to inform the relevant customers that they had gone over their poundage, but that we would forgive the balance on their account. This proved to be a good decision as over 70% of our non graduating customer base returned the next year.

Being ambiguous about pricing is a great way to irritate and ultimately drive away your customer base.

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. It was developed with the help of some Django Snippets and Ara Anjargolian.

“Read in Store” Needs More Stores

Barnes and Nobel announced a potentially awesome feature for NOOK this morning: “Read in Store” – the ability to read any ebook while you’re in a brick and mortar Barnes and Nobel location. I qualify this feature as potentially awesome because at the moment, it’s a pretty slim offering. I can already read pretty much any ebook I want while I’m at a Barnes and Nobel, and I don’t even have a NOOK – Barnes and Nobel is filled with print-outs of them.

The way this announcement reaches full potential is with the right partnership. “Read in Starbucks” seems like a no-brainer. They are already equipped with wifi, and they already have the ability to offer it for free to specific devices. It’s actually pretty surprising that this partnership (or something similar) wasn’t announced this morning with the “Read in Store” launch.

I suppose you could make the argument that it would cannibalize ebook sales because someone could just go from Starbucks to Starbucks and read an entire novel without paying for it, but people who want to steal content are going to find a way to do it. As I mentioned earlier in this post, I could walk into a Barnes & Nobel and read an entire book in print without paying for it. At least with a partnership like “Read in Starbucks”, if I  were going to steal a book, it would mean I already bought a NOOK. #Unintentional Rhyme

Can JumpPost Make Renting Less Terrible?

When you want to rent in New York city, there is no way to get a comprehensive list of available apartments. You usually have to go through a broker, but most brokers are incompetent at best and completely unethical on average. The alternative is craigslist, but the listings are mostly fake; they are just a way for brokers to collect phone numbers and email addresses. Plus, these brokers all have the same listings: a convertible 2br in stuy-town that they claim is a **OMG TRUE 3-BR IN UNION SQUARE**MUST SEE**WILL RENT TODAY . (Apparently rental brokers in New York don’t understand capital letters and the fact that they are usually reserved for the first letter of proper nouns or the beginning of a sentence.)