Corinne’s 2nd Birthday!

March 18, 2017 9:47 am

Corinne turned 2 yesterday.  The night before, she decided sleep was for the weak and stayed up 4 hours past her bedtime.  She was happy as could be, but she needed to be asleep.  The consequences were felt the next day.

Also, being St. Patrick’s Day, Heather had special activities at school and was totally worn out by the time she got home.  (She did not manage to catch any leprechauns either at home or at school.)

Corinne doesn’t seem to have a favorite food other than grabbers, so we tried Chick-fil-A for dinner.  She wasn’t interested in any of the food.  She did have fun wandering around the restaurant though.

So then it was home for presents and cake.  She very much enjoyed opening presents.

(FYI: If you know kids that like My Little Pony Friendship is Magic, seasons 1-3 are only $12 each on Amazon; which is not only reasonable, but a good price, especially for a kids’ show where the norm seems to be to gouge.)

But things went downhill when we started singing Happy Birthday.

And Heather was saddened by the whole thing too:

Corinne’s been sick on and off since Christmas.  This week she got her third ear-infection diagnosis in that time frame.  Hopefully her future birthdays are a little healthier and more enjoyable.

A Hike up Brushy Peak

February 26, 2017 7:37 pm

I went for a hike at Brushy Peak Regional Preserve today.  Water is still just coming out of the hills and turning trails into mud, but it was only a few places that were really bad.  I made it about 3.5 miles before I couldn’t keep my feet dry anymore.  Luckily, I only had another half mile to go so I didn’t end up with massive blisters.  But my shoes were covered with mud.

The path runs through cattle grazing land up in the hills above Livermore.  I started taking pictures of the cows.  They became quite interested in me and started forming a circle around me.  I was getting a little concerned, but they shooed away when I got up to leave.

Several times I came across a few cows just hanging out on the path daring you to approach them.

I started on the West Loop Trail and then transferred to the Brushy Peak Trail where I found a copse of trees growing around the stream as it tumbled down the hill.  So I took a rest and then pulled out my tripod to take some more “smooth” water pictures.

Once I packed up and got moving again I reached the highest part of the path (it doesn’t actually go to the peak as far as I could tell).  Some nice views of Livermore from up in the hills, especially while everything is still green.

Then it was down again and through the mud to get back to the parking lot.  I hiked a little over 4 miles and it took me about 4 hours.  I wasn’t intending to hike that far or be out that long, but there weren’t a lot of options for trails and hiking a trail and then just turning around is lame.  My legs are going to be sore tomorrow though.  Surprisingly I don’t seem to have a sunburn.

Up Mt. Diablo

February 18, 2017 10:25 am

Last weekend we had a break in the rain and decided to get out of the house.  So we loaded up in the van and drove up Mt. Diablo (we’ve never been up before).  And then hiked around the top.

From the observation deck, which appears to be almost brand new.  The view is pretty spectacular, especially when everything is green.

I let Heather use my binoculars and she thought it was pretty great to look at anything and everything through them–even if it was only 3 feet away.

Out hiking the summit-loop trail:

Corinne thought climbing rocks and walking the paths was pretty awesome, but that wasn’t going to be feasible once we got on the actual trail around the summit.  She wasn’t enthused about the backpack at first, but once we got moving she was fairly pleased.

It was nice to get out and about, even if it took almost an hour to get up the mountain.  There was a line at the entrance gate that was moving incredibly slowly.  And then while we were waiting an ambulance and fire truck came up and passed us.  I’m sure taking the firetruck up the mountain with all the switchbacks and narrow lanes must have been fun.  I’m not sure what the correct protocol would have been if you had met the firetruck while coming down as the firetruck was coming up on the wrong side while passing all of the cars stopped waiting for the gate.  There wasn’t room to go anywhere except in reverse.

The firetruck came down shortly thereafter, but we never saw the ambulance again.  So it must have gone down the northern entrance.

Django Form Label for Many-to-Many with Extra Fields

January 12, 2017 11:36 am

I’m working on a Django application at work that has several Many-to-Many relationships that have extra fields attached to them. Setting this up using the “through” parameter on the field definition is described in the Django documentation.

My trouble came in when it came time to render this information out to the user in a form so they could update the extra fields.  From the user’s perspective the relationship can’t be changed, but the extra fields could be.

Extending Django’s example usage about band membership, if the user were viewing the information for “The Beatles” and including a formset for all band members the form would normally render something like this:

Group Name: The Beatles
Members:
    Group: The Beatles
    Person: Ringo Starr
    Date Joined: 14 August 1962
    -
    Group: The Beatles
    Person: John Lennon
    Date Joined: 01 August 1960
    -
    [etc.]

But this is a little obtuse if the purpose of the form is to allow the user to edit the “Date Joined” value for each band member.  We can whittle the form down by telling the formset to only render the “Date Joined” field [by passing fields=(‘date_joined’,) to modelformset_factory], but then we get this:

Group Name: The Beatles
Members:
    Date Joined: 14 August 1962
    -
    Date Joined: 01 August 1960
    -
    [etc.]

Now we can’t tell to which person each date applies.

Adjusting the form so that the label “Date Joined” was instead the appropriate band members name seems like such a simple thing to change.  But I didn’t want to hand-write the form as it was already being automatically built and rendered for me using using modelformset_factory and Crispy-Forms.

It took me most of a day to figure it out and in the end it was pretty simple.  I only need to implement a custom Form that overrides the constructor and sets the label using the object instance before it gets thrown away:

class MembershipForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(MembershipForm, self).__init__(*args, **kwargs)
        if kwargs['instance'] and kwargs['instance'].person:
            self.fields['date_joined'].label = kwargs['instance'].person.name
        else:
            self.fields['date_joined'].label = 'No Person'
    class Meta:
        model = Membership
        fields = ['date_joined']

And now our output looks something like:

Group Name: The Beatles
Members:
    Ringo Starr: 14 August 1962
    -
    John Lennon: 01 August 1960
    -
    [etc.]

Since it took me most of a day to figure this out, and I couldn’t find anything specifically addressing this on the Internet, I wrote this up so hopefully the next person (or me in the future once I’ve forgotten this) will have an easier time figuring it out.