diff options
author | Dan McGee <dan@archlinux.org> | 2011-03-29 17:39:59 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-04-07 17:04:00 -0500 |
commit | 6fe08cd68901e698f4a0741e177354a45c753b46 (patch) | |
tree | 28a464e34823b62a1fcf5b26b02174b477ec10be /main/models.py | |
parent | ac550af4c9b31fe85b783d846adad75bb7d4aa02 (diff) |
Utilize Django 1.3 'on_delete' feature on several foreign keys
The most important one here is PROTECT to keep people from making
bone-headed plays and deleting an Arch or Repo and every package along
with it. We can use this in a few other places, as well as some
carefully placed SET_NULL indicators.
Note that nothing here pushes deletion responsibilities down to the
database, although that will probably happen in a future commit.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main/models.py')
-rw-r--r-- | main/models.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/main/models.py b/main/models.py index 38120134..772d85bb 100644 --- a/main/models.py +++ b/main/models.py @@ -104,8 +104,10 @@ class Repo(models.Model): verbose_name_plural = 'repos' class Package(models.Model): - repo = models.ForeignKey(Repo, related_name="packages") - arch = models.ForeignKey(Arch, related_name="packages") + repo = models.ForeignKey(Repo, related_name="packages", + on_delete=models.PROTECT) + arch = models.ForeignKey(Arch, related_name="packages", + on_delete=models.PROTECT) pkgname = models.CharField(max_length=255, db_index=True) pkgbase = models.CharField(max_length=255, db_index=True) pkgver = models.CharField(max_length=255) @@ -121,7 +123,8 @@ class Package(models.Model): last_update = models.DateTimeField(null=True, blank=True) files_last_update = models.DateTimeField(null=True, blank=True) packager_str = models.CharField(max_length=255) - packager = models.ForeignKey(User, null=True) + packager = models.ForeignKey(User, null=True, + on_delete=models.SET_NULL) flag_date = models.DateTimeField(null=True) objects = PackageManager() @@ -348,7 +351,7 @@ class PackageDepend(models.Model): db_table = 'package_depends' class Todolist(models.Model): - creator = models.ForeignKey(User) + creator = models.ForeignKey(User, on_delete=models.PROTECT) name = models.CharField(max_length=255) description = models.TextField() date_added = models.DateTimeField(db_index=True) |