Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6755: model inheritance now works in the admin. Thanks, sloonz…

… and Michael Placentra.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8033 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 863f4eb1d7cf96013207986c7f848defde16210d 1 parent c236874
Jacob Kaplan-Moss authored July 22, 2008
2  AUTHORS
@@ -303,6 +303,7 @@ answer newbie questions, and generally made Django that much better:
303 303
     phil@produxion.net
304 304
     phil.h.smith@gmail.com
305 305
     Gustavo Picon
  306
+    Michael Placentra II <someone@michaelplacentra2.net>
306 307
     Luke Plant <http://lukeplant.me.uk/>
307 308
     plisk
308 309
     Mihai Preda <mihai_preda@yahoo.com>
@@ -342,6 +343,7 @@ answer newbie questions, and generally made Django that much better:
342 343
     jason.sidabras@gmail.com
343 344
     Jozko Skrablin <jozko.skrablin@gmail.com>
344 345
     Ben Slavin <benjamin.slavin@gmail.com>
  346
+    sloonz <simon.lipp@insa-lyon.fr>
345 347
     SmileyChris <smileychris@gmail.com>
346 348
     smurf@smurf.noris.de
347 349
     Vsevolod Solovyov
6  django/db/models/base.py
@@ -299,6 +299,12 @@ def save_base(self, raw=False, cls=None):
299 299
         # attributes we have been given to the class we have been given.
300 300
         if not raw:
301 301
             for parent, field in meta.parents.items():
  302
+                # At this point, parent's primary key field may be unknown
  303
+                # (for example, from administration form which doesn't fill
  304
+                # this field). If so, fill it.
  305
+                if getattr(self, parent._meta.pk.attname) is None and getattr(self, field.attname) is not None:
  306
+                    setattr(self, parent._meta.pk.attname, getattr(self, field.attname))
  307
+
302 308
                 self.save_base(raw, parent)
303 309
                 setattr(self, field.attname, self._get_pk_val(parent._meta))
304 310
 
1  django/db/models/fields/related.py
@@ -706,6 +706,7 @@ class OneToOneField(ForeignKey):
15  tests/regressiontests/model_inheritance_regress/models.py
@@ -159,4 +159,19 @@ class Child(Parent):
159 159
 ...
160 160
 DoesNotExist: ItalianRestaurant matching query does not exist.
161 161
 
  162
+# Regression test for #6755
  163
+>>> r = Restaurant(serves_pizza=False)
  164
+>>> r.save()
  165
+>>> r.id
  166
+3
  167
+>>> r.place_ptr_id
  168
+3
  169
+>>> r = Restaurant(place_ptr_id=3, serves_pizza=True)
  170
+>>> r.save()
  171
+>>> r.id
  172
+3
  173
+>>> r.place_ptr_id
  174
+3
  175
+
  176
+
162 177
 """}

0 notes on commit 863f4eb

Please sign in to comment.
Something went wrong with that request. Please try again.