Fix creation of new objects with notifications that have ManyToMany relationships
authorMagnus Hagander <magnus@hagander.net>
Thu, 20 Jun 2013 10:29:27 +0000 (12:29 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 20 Jun 2013 10:29:27 +0000 (12:29 +0200)
This broke in django 1.4 since it fires based on the contents of an error message,
and the message changed. Most visible due to the fact that it completely broke
creation of new organsation objects.

pgweb/util/bases.py

index ec2fa9610a31b83df1202315d26a4c70ec08af54..f9dfa506a1b0a452549f1c793a0c618afd85c71b 100644 (file)
@@ -126,7 +126,9 @@ class PgModel(object):
                except ValueError, v:
                        # NOTE! If the object is brand new, and it has a many-to-many relationship, we can't
                        # access this data yet. So just return that it's not available yet.
-                       if v.message.find('instance needs to have a primary key value before a many-to-many relationship can be used') > -1:
+                       # XXX: This is an ugly way to find it out, and is dependent on
+                       #      the version of django used. But I've found no better way...
+                       if v.message.find('" needs to have a value for field "') and v.message.find('" before this many-to-many relationship can be used.') > -1:
                                return "<not available yet>"
                        else:
                                raise v