Django error: TemplateResponseMixin requires either a definition of ‘template_name’ or an implementation of ‘get_template_names()’

This is such a bizarre error message and I have spent hours trying to figure out what on earth I’ve been doing wrong. This is my situation: I have several models for which I am creating generic views for (ListView, DetailView, CreateView, UpdateView, DeleteView). These mostly contain postgis geographical data that I am storing as¬†polygonfields and so on. To display these nicely in my forms I want to use the django-leaflet LeafletWidget. To do THIS I have to create a modelform. So for example my files look like:

models.py:

class Project(models.Model):
    current_name = models.CharField(max_length=50)
    location = models.PolygonField()
    objects = models.GeoManager()

views.py:

class ProjectCreate(CreateView):
    model = models.Project
    template_name_suffix = '_create_form'
    form_class = forms.ProjectCreateForm

forms.py:

class ProjectCreateForm(forms.ModelForm):
    class Meta:
        model = Project
        fields = ('current_name', 'location')
        widgets = {'location': LeafletWidget()}

urls.py:

urlpatterns = [
    url(r'^project/create$', views.ProjectCreate.as_view(), name='project_create'),
]

now, if you leave out the model = x bit in the createview (which i think is perfectly reasonable as you have to specify in the modelform in the forms.py what model you want to use, then you get this error:

TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'

Absolutely infuriating. I can’t believe how many hours it took for me to track this down. All because I left it yesterday and didn’t put the model = x bit back into the code when I removed it to see what happened. I also can’t believe I actually forgot about it though – senility is clearly on the horizon.

It is actually in the docs though – https://docs.djangoproject.com/en/1.8/topics/class-based-views/generic-editing/ scroll down to the first note inset. Lesson learned: always read the docs rather than googling for stackoverflow answers!

Terry Pratchett

You know, I can’t believe both Terry Pratchett and Diana Wynne Jones are gone now. Two people whose books I would look forward to and read on a regular basis. I hope we see their like again, but I just haven’t found any authors who I enjoy in the same way.

A lot of people I know, most people actually, didn’t really like Pratchett’s writing. And I can sort of understand, the books are a bit jarringly zany, but if you’re the kind of person who can quite happily be carried off on a madcap adventure then you will enjoy them.

He certainly wasn’t the most subtle writer in the world, but I loved his force and his vitriol and his complete disdain for the crap people can come up with. It’s purer and raw-er than most of the other authors I like, but I don’t enjoy it any less at all.

And really the books were very clever, they skewered everything that was wrong with the world and stuck it on a cork board for everyone to laugh at. And he had so much colour and diversity in his books, and so many different kinds of people and different ways of making fun (and I mean that in the literal sense, as in, he manufactured fun and happiness and wonderfulness) of them.

Well I feel quite sad now.

WordPress, you suck for websites with lots of pages and no posts

My recent experiences with wordpress have made me realise that it really is a terrible solution for a website with a lot of pages (say more than 30) and no posts. It’s great at blogging though. But say you have lots of pages, you’re gonna want a menu to show those pages right? And you’re probably going to want 2 menus, one for the ‘about/contact/partners/faq’ to-do-with-the-company content, and one for the primary content. If your primary content custom menu is likely to be long (as it is in my case, at around 130 pages+), then the default menu system is cumbersome and dragging things around between levels is a complete nightmare.

And there is no solution. You can display page hierarchies instead, but this sucks because it’s useful to think about your site in terms of the menu structure, and to do half of your menus using custom menus and half of your menus using page hierarchy is shit. It’s also impossible to get your menus to automatically sync with your page hierarchy. I miss drupal. Here’s hoping this post annoys someone enough for them to post and tell me an easy way of doing what I want (just a simple menu which is easy to manage!).

Django 1.7 and Python 3.4 how to add a label class to your ModelForm using crispy forms

There’s a bug that’s described here: http://stackoverflow.com/questions/22901745/django-crispy-forms-bootstrap-helper-label-class-and-helper-field-class-not-wo

which can be “fixed” by changing crispy_forms/templates/bootstrap/field.html on line 8 from:

<label for="{{ field.id_for_label }}" class="control-label {% if field.field.required %}requiredField{% endif %}">

to

<label for="{{ field.id_for_label }}" class="control-label {% if field.field.required %}requiredField{% endif %}{% if label_class %} {{ label_class }}{% endif %}">

I have no idea how to get field classes working, frankly. But it is possible to get a fieldclass using django by passing it in through a widget thank goodness. Like so:


class BookForm(forms.ModelForm):
class Meta:
model = Book
exclude = ('unecessary_field')
widgets = {
'published': forms.TextInput(attrs = {'class': 'col-lg-8-or-whatever'}),
}

Took me ages to work this out. I hope it helps someone.

Sexism in The Big Bang Theory

I’ve really tried to like this show. I’ve had it recommended to me so many times by so many different people. But I just don’t get how anything so lazy and tired and boring can be funny, and my goodness I find the sexism really offensive.

Maybe it’s because I’m into fantasy books, sci fi shows, video games and I’m a programmer in my day job. I am fed up to the back teeth of women being portrayed as bimbo airheads who are only interested in clothes and guys and who would never get nerdy computer/maths/physics references. TV is FULL of these stupid stereotypes which are harming our society (yes, yes they are). Do we really need another show with them? I surely can’t be the only person who’s bored of them?

I’m not of course (this is a really good article) but in all the universal acclaim it feels like I am. Even the Guardian, my favourite newspaper, seem to like the show. And well, you know, possibly it does get better later on, but I couldn’t force myself to watch any more than the first 3 episodes it was so painful.

On the other hand there is a silver lining. Shows like this are why I still find programmes poking fun at blind, backward, sexist men – like the 90s Irish “Father Ted” for example – absolutely hilarious. Hurrah!

Compulsion games’ Contrast

I have no idea why this game seems to have got so little attention and praise. It is excellent, the concept is incredibly cool (you are a little girl’s imaginary friend who can slip into shadows), the dialogue and writing is awesome and hilarious and the voice acting is great. Even the plot is pretty cool. The gameplay is a bit iffy at times but it’s so original and so clever that I can certainly forgive that.

One of my favourite scenes in the game is where you end up having to play as a cut-out paper character in a little theatre (games within games, people). You play as the princess, and there’s a handsome prince who has come along to win your hand in marriage from your father. But the prince turns out to be absolutely useless, and you as the princess end up having to go off on adventures and kill dragons and whatnot to save him. It’s really well done, really funny, and the way bouncing up animation of the prince whenever he gets rescued is hilarious and endearing. And so the princess decides to give this useless prince a try, although the narrator lets us know that in another story the princess says “screw this” and goes off adventuring on her own. It is so rare to find that kind of approach to female characters in games, I cannot tell you.

I really loved the characters too, the little girl (Didi), who is very solid and real feeling, as well as the mother. Johnny was a bit more of a caricature, but Vincenzo was super as well. The relationships were realistic, maybe a little overly dramatic but that added to the fun. The noir atmosphere and jazzy bits of the soundtrack were sooooooo cool as well. The gameplay sometimes made the puzzles a little frustrating, but apart from that it was top-notch! And yet critics only scored it 59% on metacritic. The world is inexplicable.

I don’t want to go all conspiracy theorist, but I kind of feel as if it’s been dismissed a bit because you play as a female character, and the other lead character is a little girl. Maybe I’m wrong though, maybe I just have a completely different taste in games to the rest of the world, maybe I’m being extra kind to it because I enjoyed playing a game with strong female characters. But check this out: “Feminist/lesbian agenda – Does this game contain feminist or LGBT agenda? This will affect my buying decision. The game looks very promising though.” http://steamcommunity.com/app/224460/discussions/0/810938810495435947/ YUCK.

Zambia and Zimbabwe

I went on a trip to Victoria Falls recently. One of these days I will get the hang of doing proper travel writing and actually say stuff, but in the meantime here is a baboon and his bag which I saw at the falls:

Baboon and his bag

Baboon and his bag

A Suitable Boy by Vikram Seth

In the wake of the stress and flurry of handing in the second draft of my thesis, I have treated myself to finishing A Suitable Boy by Vikram Seth. I really enjoyed the novel, and I don’t really think it was overly long despite everyone complaining about it. Am I the only person who quite likes long novels? I could happily have sunk into that world for another thousand pages or so! The writing style reminded me a little of RK Narayan, maybe in my head I just associate the two because of their nationality though.

Continue reading

Three months of adventure, penguins, tinned food and no showers on the incredible Nightingale Island

Late last year I had the privilege of collecting field data for my Conservation Biology MSc thesis on Nightingale Island. I kind of shot myself in the foot a bit with that because it meant I had 3 months less time to write up than all of my classmates. I have little to no experience writing up scientific papers, and although I have good writing skills in general I’ve learned that scientific writing is a peculiar beast which requires weeks of sweat, blood and tears (oh, so many tears!) to wrestle into submission for those who have not encountered it before. I’ve had to get an extension for my write-up – I am very lucky that my supervisors are so kind, supportive and helpful – but living on Nightingale and working with the penguins was worth all of the trouble a thousand times over.

Continue reading