johnmnemonik / django-photologue

Automatically exported from code.google.com/p/django-photologue
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Deleting photo also deleted a custom model instance linked via a ForeignKey #74

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Using admin interface, select photo linked to custom model instance via
ForeignKey.
2. Delete photo using admin interface.
3. Custom object instance now also deleted.

What is the expected output? What do you see instead?

  Photo only should be deleted. Instead, the custom object instance is
deleted too.

What version of the product are you using? On what operating system?

  django-photologue 2.0 running on FreeBSD with Django 1.0

Please provide any additional information below.

I attach a screenshot of my "Recent actions" showing the deletion of the
photo WSUV, the addition of an different version of the photo (with the
same name), and finally the re-addition of the "Fieldsite" which had been
inadvertently deleted.

I did not "deselect" the photo in my instance prior to deleting the photo.
I have nothing fancy in admin.py.

Here is my import statement:

  from photologue.models import Gallery, Photo

And here is the custom model:

class Program(models.Model):

    Title = models.CharField(max_length=100)
    Slug = models.SlugField(max_length=20, unique=True, help_text="The last
part of the URL. This must be a single word with no spaces or punctuation")
    Summary = models.CharField(max_length=200, help_text="Brief, one
sentence summary.")
    Description = models.TextField(help_text="Format text using Markdown.
For help with Markdown click the link at the top of this page.") #
Description should be in Markdown format
    Photo = models.ForeignKey(Photo, null=True, blank=True)
    Photo_gallery = models.ForeignKey(Gallery, null=True, blank=True)
    List_in_navbar = models.BooleanField(default=False, help_text="Link to
this page in the left-hand navigation area.")
    List_on_participants_page = models.BooleanField(default=False,
help_text="Should this program be linked on participants' pages?")
    Parent_program = models.ForeignKey('self', null=True, blank=True)
#   Program_owner = models.ForeignKey(Academic, null=True, blank=True,
help_text="The person who runs this program. Can be left blank.")    
    sites = models.ManyToManyField(Site)
    Program1 = models.CharField(max_length=100, blank=True)
    Program2 = models.TextField(blank=True)

    def get_absolute_url(self):
        return 'program/' + self.Slug     

    def __unicode__(self):
        return self.Title

Original issue reported on code.google.com by eha...@gmail.com on 10 Oct 2008 at 10:51

Attachments:

GoogleCodeExporter commented 8 years ago
I believe the problem lies not in Photologue but in Django.  The latter always
performs deletes as though ON DELETE CASCADE had been specified for all foreign 
keys.
 As far as I know the only way to avoid this is to manually NULL references to the
row being deleted before performing the deletion.

http://docs.djangoproject.com/en/dev/topics/db/queries/#deleting-objects

Original comment by ma...@two14.net on 10 Aug 2009 at 3:26