Hi!
I see it very common and good to extend some base models by OneToOne
relations. So, for example, in my application I am using django
contrib.auth. All my users also have 'instituton' field. All works,
except
inline editition of code. Here is example:
----------------------- Customer/models.py
---------------------------------
from django.db import models
from django.contrib.auth.models import User
from OneToOneTest.Customer.signals import create_default_customer
from django.dispatch import dispatcher
from django.db.models import signals
from django.contrib.auth import models as user_app
class Customer(models.Model):
user = models.OneToOneField(User,edit_inline=True)
institution = models.CharField(maxlength=40,core=True)
dispatcher.connect(create_default_customer, sender=User,
signal=signals.post_save)
------------------------ Customer/signals.py
---------------------------------
def create_default_customer(sender, instance, signal, *args,**kwargs):
from djWarehouse_custom.Customer.models import Customer
customer,is_added = Customer.objects.get_or_create(user=instance)
#, institution='n/a')
if is_added:
customer.institution='n/a'
customer.save()
Adding customer works fine, but attempt to save gives this error:
Exception Type: KeyError
Exception Value: 'user'
Exception Location:
/usr/lib64/python2.4/site-packages/django/db/models/manipulators.py in
save, line 163
Obviously, this is because Manipulator tries to use related field ID as
for ForeignKey, but it
seems to be wrong approach, since with OneToOne field we should
directly search on User.
I have tried to change the code to something like this:
http://dpaste.com/3858/
And it works fine for me, but probably thats not the best way to fix it
(?) since my code is using type
check.
Should I submit bug report? I have searched current bug reports, but I
do not find anything related.
Regards,
Alex
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---