Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2199 closed defect (fixed)

[patch] Can't delete generic foreign key in Admin

Reported by: parlar@… Owned by: Jacob
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using the new generic foreign key stuff, I can't delete my foreign keys.

My model is as follows:

class AuthUser(models.Model):
    user = models.ForeignKey(User)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = models.GenericForeignKey()
   
    class Admin:
        list_display = ('user', 'product_name')

    
    def product_name(self):
        return self.content_object.product_name
        

    def __str__(self):
        return self.user.username
        
class Product(models.Model):
    product_name = models.CharField(maxlength=64, blank=False, unique=True )
    users = models.GenericRelation(AuthUser)

After creating a few relations between Products and AuthUser (much like the Tag example given in the tests), I try to delete one of the AuthUsers via the Admin, and get the following:

Traceback (most recent call last):
File "/home/parlarjb/lib/python2.4/django/core/handlers/base.py" in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "/home/parlarjb/lib/python2.4/django/contrib/admin/views/decorators.py" in _checklogin
  54. return view_func(request, *args, **kwargs)
File "/home/parlarjb/lib/python2.4/django/views/decorators/cache.py" in _wrapped_view_func
  40. response = view_func(request, *args, **kwargs)
File "/home/parlarjb/lib/python2.4/django/contrib/admin/views/main.py" in delete_stage
  500. _get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1)
File "/home/parlarjb/lib/python2.4/django/contrib/admin/views/main.py" in _get_deleted_objects
  465. for sub_obj in getattr(obj, rel_opts_name).all():

  AttributeError at /admin/oidgenerator/authuser/1/delete/
  'AuthUser' object has no attribute 'product_set'

Attachments (2)

related.diff (3.0 KB ) - added by parlar@… 18 years ago.
[patch] Corrects the error
related_fix.diff (2.6 KB ) - added by parlar@… 18 years ago.
[patch] Fixes a small problem with the original path

Download all attachments as: .zip

Change History (7)

comment:1 by James Bennett, 18 years ago

AFAIK the generic foreign key stuff is still in the "fleshing out" phase; in particular, working with it in the admin will be spotty.

comment:2 by parlar@…, 18 years ago

That's what I figured, but it's probably still worthwhile to document the issues we run into.

by parlar@…, 18 years ago

Attachment: related.diff added

[patch] Corrects the error

comment:3 by parlar@…, 18 years ago

Summary: Can't delete generic foreign key in Admin[patch] Can't delete generic foreign key in Admin

The patch I added corrects the problem for me, at least.

With the patch, I can now delete AuthUsers. I can also delete Users, and all the associated AuthUsers will be deleted.

I don't know if this is the proper way to do it, but it's what I've got to use for now.

by parlar@…, 18 years ago

Attachment: related_fix.diff added

[patch] Fixes a small problem with the original path

comment:4 by parlar@…, 18 years ago

My original patch (related.diff) had a stray debugging 'print' statement in it. The most recent patch (related_fix.diff) should be used instead.

comment:5 by Jacob, 18 years ago

Resolution: fixed
Status: newclosed

Fixed in [3194]

Note: See TracTickets for help on using tickets.
Back to Top