#11807: Admin inlines onetoone related object not saved
----------------------------------------------+-----------------------------
          Reporter:  neme...@twilightzone.lu  |         Owner:  nobody          
          
            Status:  new                      |     Milestone:                  
          
         Component:  django.contrib.admin     |       Version:  1.1             
          
        Resolution:                           |      Keywords:  admin inline 
onetoone save
             Stage:  Design decision needed   |     Has_patch:  0               
          
        Needs_docs:  0                        |   Needs_tests:  0               
          
Needs_better_patch:  1                        |  
----------------------------------------------+-----------------------------
Changes (by kmtracey):

  * stage:  Unreviewed => Design decision needed

Old description:

> Hi there,
>
> I have the following models:
>
> class A(models.Model):
>    id = models.AutoField(primary_key=True)
>
> class B(models.Model):
>    mya = models.OneToOneField(A, primary_key=True)
>    text = models.TextField(default='Init')
>
> In admin interface, I have used an inline to include B when
> changing/adding an A. Adding/Changing an A without touching the B inline
> results in A beeing saved, but not B. Changing the textfield from B into
> sth other than default and it works, but I want the default beeing saved
> too.
>
> Thanks!
> Jean

New description:

 Hi there,

 I have the following models:

 {{{
 #!python
 class A(models.Model):
    id = models.AutoField(primary_key=True)

 class B(models.Model):
    mya = models.OneToOneField(A, primary_key=True)
    text = models.TextField(default='Init')
 }}}

 In admin interface, I have used an inline to include B when
 changing/adding an A. Adding/Changing an A without touching the B inline
 results in A beeing saved, but not B. Changing the textfield from B into
 sth other than default and it works, but I want the default beeing saved
 too.

 Thanks!
 Jean

Comment:

 First, I fixed the description formatting.  Please use preview (and wiki
 format) to make sure things are readable before submitting.

 Replying to [comment:1 AdamG]:
 > My guess is that `BaseModelFormSet.save_existing_objects()` is skipping
 the form because `form.has_changed()` is False.

 Yes the problem is likely related to the fact that the form has not been
 changed, though I think it is the has_changed in save_new that is causing
 the issue here.  Thing is, if nothing has changed, how is the admin code
 supposed to figure out that a new item should be created?  I don't believe
 it is always the case that you'd want admin creating objects with all
 defaults (actually I'm pretty sure there was once a bug because admin did
 that).  I am not sure that the admin interface, as it currently exists,
 supports what is being asked for here.  There is currently no explicit
 "add this item" checkbox (as there is for delete), thus the admin has to
 figure out the right thing to do.  It does that now by seeing if anything
 has changed since the form was presented to the user.  If yes, then an
 object is added.  If no, then no new object is created.  I don't quite see
 how to support this use case, and also the case where you don't want all-
 default objects created (which is also valid), without a pretty
 significant change in the admin interface here.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11807#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to