Django modelformset is powerful!

I spent two days trying all kinds of non-sense trying to setup a form for entering the temperature profile steps. In the end, it turns out using modelformset is so easy! No need to setup extra form for each model. No need to keep tracking which form is initialized by which object.  Two lines take care of everything!

RecipeSet=modelformset_factory(Recipe,extra=7,max_num=8)
n=RecipeSet(queryset=Recipe.objects.all().order_by(‘step’))

Django rocks!

a Saturday morning reflection

A few year back, a friend opened an art gallery for about half an year. It didn’t prevail. This morning it came across to my mind. As a witness to history, I can see several more things now from what I learnt between now and then.

The focus has been placed around art rather than on art. The idea emerged as “seeing a trend coming”. The store is located in a upraising neighborhood. There are many art galleries opened around the area. So the hope was that they will attract tourists and buyers to the area. This concept has no problem. But the core competition with this approach will be laying on the quality of the art work acquired and the salesmanship. Because the purpose behind this concept is hoping to “sell”, rather than “promoting” art. So without external fund support, the high burning rate eventually killed the operation.

What could have been done differently?

1. Getting the store front vs not getting it. Getting the store front actually is some how the starting point. It provided an anchor. It provided credibility up to a certain level. But the cost is a higher burning rate, which later on became a burden. (The friend also invested quite some money to renovate the space. This can be argued as an unappreciated action in The Lean Startup model.)

2. Getting customers vs getting artists. This is a chicken and egg problem. With the store front, indeed the two sides meet. But they didn’t trade. The tone of the operation had been set on “waiting”, because it is believed that selling art is not selling life-insurance. So you shouldn’t up sell your customers.

3. Didn’t obey the first dollar rule. As mentioned before, some resources has been allocated on non-essential tasks. (Or said the decision has been made without marketing research or market validation.) For example, the renovation. The most essential question, how to make the first dollar, has been procrastinated.

All these are after thoughts. Basing on the expertise and knowledge of the group at that time, I don’t know how we could have done better at that point. So, the biggest lesson might be: don’t enter a business in which you (and also important, your friends) are not the expert. If you want to start a business, start it around your core competence.

law and moral standards are set against personal interests by definition

Law, moral standards and etc. are all set for public welfare (either for human species or a subgroup). They will go against certain group of people’s personal interests by definition. Because if it is to your benefit, you would do that automatically. For example, we can, but we don’t need to set a law saying that people should go eat when they feel hungry. But we set a law saying that you CANNOT eat someone else’s food without their permission. In a plain language: there’s no need to regulate people to do something people would do anyway.

This, leads to an interesting question — marriage. With above being said, it implies that getting married and obey the vow and comply with the law is going against your personal interest. But, most people get married anyway. The society approve these people because it is for the good of the entity human society – you reproduce the offspring and you educate them for the society and etc – you do your duty, good. On the same time, this is also a main reason for the singles who passed their “should get married age” and LGBT people to bear social pressure, because they put freedom or love or some other reason – something that can be argued as more personal interest, above their “making offspring duty”.

Notice here, for married people who have affairs, they got blamed not because they are not allowed to pursuit love or happiness or whatever. They received criticism because they failed to comply to another rule: the society expect you to do what you said you would do, obey your vow and be responsible. If you manage to make your wife happy and your children well educated, in principal, you should get treated as “who cares what you do after hours?” However, that’s not the case, the society still can’t give you approval even you are super rich and so on. Why? Still because of public welfare, there are some stupid people who don’t have the money/time/energy to take care of multiple wives or husbands, but still want to f*ck around. If the society publicly gives green light to some people but not others, there will be an uproar.

When you read to here, are you thinking it is unfair? Well, in other situations, the protocol for handling this kind of situation is to make tiers and differentiation. For example, in paying salary, you get paid more if you work harder (in principal). So why this is not happening here? Well, my guess is that there are too many reasons people are reluctant to bring up this issue to a level that requires a change (People just talk, it will take a lot of courage for someone to lead such a reform movement. So bottom-up is hard.), and the law makers doesn’t think this is a big enough problem because they charge fees on both getting married and getting divorce (No top-down motivations).

Do you think this is the underlying reason for “Marriage is the tomb of love“? With the divorce rate rockets up, does it come to a time for the society to rethink about marriage and change the regulation?

Share your opinion.

Beginner’s Guide from physicist (1): Sheng Ji’s first-time players’ strategy cheatsheet (升级上手指南)

There is a popular card game in Chinese community called “Sheng Ji“. The rules are very involved, especially for first-time players (at least for me at the beginning). After some trial and errors, I summarized the strategy in the following:

1. There are only two teams. (Let’s call them A and B.)

2. A round can only end up in two states: Team A wins, or team B wins.

3. Thus, points can only end up in two states: Team A gets all the points of the round, or team B gets all the points of the round.

cheatsheet for first-time Sheng Ji player

cheatsheet for first-time Sheng Ji player.

That says, in order for a first-time player to play along, there is only one measurement he/she has to perform in his/her turn of playing (besides remembering the ranking of the cards):

Measurement: Is his/her team winning this round? The answer can have only three possible results: YES, NO, NOT SURE.

If YES, the strategy is to maximize the points in this round, i.e., throw out all the point cards in hand which are allowed to play in this round (how to determine what are allowed, is out of the scope of this letter).

If NO, the strategy is to minimize the points in this round, avoid playing point cards if possible, i.e., throw out garbage cards.

If NOT SURE, then the ranking of the actions is in the following order:

a. Trying to win this round, for two reasons, to secure the points in this round, and/or to take the lead for next round.

b. If no chance of winning, then take a bet, if bet on the team will win this round, then play point cards, if not, then play garbage cards.

There are more advanced techniques like communication with the teammates and estimate the winning chance, but those techniques are all for better playing the NOT SURE case, which only takes up maybe around 25% of time. So for a first-time player, following the above simple rules should provide him/her an enjoyable playing experience.

P.S., anyone interested in turning this into an algorithm and run a test to see how robust is the strategy?

Follow

Get every new post delivered to your Inbox.

Join 681 other followers

%d bloggers like this: