I had a similar issue, solved with a trick.
Try to explicit a save() method for your SuperDelegate this way:
def save(self, *args, **kwargs):
super(SuperDelegate, self).save(*args, **kwargs)
Giovanni
On 6 Set, 12:09, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> A foreignkey in a model with a customised objects manager is causing
> an exception when that parent model is saved.
>
> Model 'SuperDelegate' has a boolean field 'is_active'. 'Delegate'
> model has a ForeignKey to SuperDelegate. I only want to ever show
> active SuperDelegates so the objects manager has the default query
> is_active=True. Saving a SuperDelegate.is_active = False is fine. But
> trying to save is.active = True (having been false) throws the
> following exception:
>
> >>> sd = SuperDelegate.all.all()[0] # a manager to pull out
> >>> is_active=False instances
> >>> sd.is_active
> False
> >>> sd.is_active = True
> >>> sd.save()
>
> Traceback (most recent call last):
> File "<console>", line 1, in ?
> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/django/db/models/base.py", line 307, in
> save
> self.save_base(force_insert=force_insert,
> force_update=force_update)
> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/django/db/models/base.py", line 379, in
> save_base
> result = manager._insert(values, return_id=update_pk)
> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/django/db/models/manager.py", line 138, in
> _insert
> return insert_query(self.model, values, **kwargs)
> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/django/db/models/query.py", line 888, in
> insert_query
> return query.execute_sql(return_id)
> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/django/db/models/sql/subqueries.py", line
> 308, in execute_sql
> cursor = super(InsertQuery, self).execute_sql(None)
> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/django/db/models/sql/query.py", line 1700,
> in execute_sql
> cursor.execute(sql, params)
> File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> lib/python2.4/site-packages/django/db/backends/util.py", line 19, in
> execute
> return self.cursor.execute(sql, params)
> IntegrityError: duplicate key value violates unique constraint
> "delegate_superdelegate_pkey"
>
> Removing the default is_active=True objects manager removes this
> problem, so it's fine i can use a different manager for each
> SuperDelegate listing. But what's going on here? (postgresql 8.3/
> Django 1.0)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---