diff options
Diffstat (limited to 'apps/patchwork/models.py')
-rw-r--r-- | apps/patchwork/models.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 162fa21..d0c2a6e 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -289,12 +289,20 @@ class Bundle(models.Model): owner = models.ForeignKey(User) project = models.ForeignKey(Project) name = models.CharField(max_length = 50, null = False, blank = False) - patches = models.ManyToManyField(Patch) + patches = models.ManyToManyField(Patch, through = 'BundlePatch') public = models.BooleanField(default = False) def n_patches(self): return self.patches.all().count() + def append_patch(self, patch): + # todo: use the aggregate queries in django 1.1 + orders = BundlePatch.objects.filter(bundle = self).values('order') + max_order = max([ v for (k, v) in orders]) + + bp = BundlePatch.objects.create(bundle = self, patch = patch, order = max_order + 1) + bp.save() + class Meta: unique_together = [('owner', 'name')] @@ -313,6 +321,14 @@ class Bundle(models.Model): return '\n'.join([p.mbox().as_string(True) \ for p in self.patches.all()]) +class BundlePatch(models.Model): + patch = models.ForeignKey(Patch) + bundle = models.ForeignKey(Bundle) + order = models.IntegerField() + + class Meta: + unique_together = [('bundle', 'patch'), ('bundle', 'order')] + class UserPersonConfirmation(models.Model): user = models.ForeignKey(User) email = models.CharField(max_length = 200) |