Django

Code

Changeset 447

Show
Ignore:
Timestamp:
08/09/05 19:21:41 (3 years ago)
Author:
adrian
Message:

Fixed #154 -- Fixed constraint error when deleting an object with a many-to-many field

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/meta/__init__.py

    r440 r447  
    776776        cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (rel_field.get_m2m_db_table(rel_opts), 
    777777            self._meta.object_name.lower()), [getattr(self, opts.pk.name)]) 
     778    for f in opts.many_to_many: 
     779        cursor.execute("DELETE FROM %s WHERE %s_id=%%s" % (f.get_m2m_db_table(opts), self._meta.object_name.lower()), 
     780            [getattr(self, opts.pk.name)]) 
    778781    cursor.execute("DELETE FROM %s WHERE %s=%%s" % (opts.db_table, opts.pk.name), [getattr(self, opts.pk.name)]) 
    779782    db.db.commit() 
  • django/trunk/tests/testapp/models/many_to_many.py

    r445 r447  
    7070[Django lets you build Web apps easily, NASA uses Python] 
    7171 
    72 # If we delete an article, its publication won't be able to access it. 
     72# If we delete a Publication, its Articles won't be able to access it. 
     73>>> p1.delete() 
     74>>> publications.get_list() 
     75[Science News] 
     76>>> a1 = articles.get_object(pk=1) 
     77>>> a1.get_publication_list() 
     78[] 
     79 
     80# If we delete an Article, its Publications won't be able to access it. 
    7381>>> a2.delete() 
    7482>>> articles.get_list() 
     
    7684>>> p1.get_article_list(order_by=['headline']) 
    7785[Django lets you build Web apps easily] 
    78  
    7986"""