]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Add a backreference for a user's bundles
authorStephen Finucane <stephen@that.guru>
Thu, 12 Apr 2018 12:01:31 +0000 (13:01 +0100)
committerStephen Finucane <stephen@that.guru>
Wed, 25 Apr 2018 20:26:25 +0000 (21:26 +0100)
This is more intuitive.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/migrations/0026_add_user_bundles_backref.py [new file with mode: 0644]
patchwork/models.py
patchwork/views/bundle.py
patchwork/views/patch.py
patchwork/views/user.py

diff --git a/patchwork/migrations/0026_add_user_bundles_backref.py b/patchwork/migrations/0026_add_user_bundles_backref.py
new file mode 100644 (file)
index 0000000..e3dbf80
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2018-04-12 11:59
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('patchwork', '0025_add_regex_validators'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='bundle',
+            name='owner',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bundles', related_query_name='bundle', to=settings.AUTH_USER_MODEL),
+        ),
+    ]
index f91b994c8689a77a9ed082b10d44e922453685c7..5453021219a57c6cc088767ba3b9dae8e42dc886 100644 (file)
@@ -778,7 +778,9 @@ class SeriesReference(models.Model):
 
 
 class Bundle(models.Model):
-    owner = models.ForeignKey(User, on_delete=models.CASCADE)
+    owner = models.ForeignKey(User, on_delete=models.CASCADE,
+                              related_name='bundles',
+                              related_query_name='bundle')
     project = models.ForeignKey(Project, on_delete=models.CASCADE)
     name = models.CharField(max_length=50, null=False, blank=False)
     patches = models.ManyToManyField(Patch, through='BundlePatch')
index 2d18571d82d71ed03e9d6ed23d7e360e9bee22bd..5aa63fba170530e89f480392674bb3af95329468 100644 (file)
@@ -71,10 +71,10 @@ def bundle_list(request, project_id=None):
                 bundle.delete()
 
     if project_id is None:
-        bundles = Bundle.objects.filter(owner=request.user)
+        bundles = request.user.bundles.all()
     else:
         project = get_object_or_404(Project, linkname=project_id)
-        bundles = Bundle.objects.filter(owner=request.user, project=project)
+        bundles = request.user.bundles.filter(project=project)
 
     for bundle in bundles:
         bundle.delete_form = DeleteBundleForm(auto_id=False,
index 7e962e72527f8f5d7415387778a4659ab276ef1d..eccb5441559b597186af81390421b1f8a5ccd799 100644 (file)
@@ -44,7 +44,7 @@ def patch_list(request, project_id):
                            view_args={'project_id': project.linkname})
 
     if is_authenticated(request.user):
-        context['bundles'] = Bundle.objects.filter(owner=request.user)
+        context['bundles'] = request.user.bundles.all()
 
     return render(request, 'patchwork/list.html', context)
 
@@ -112,7 +112,7 @@ def patch_detail(request, patch_id):
                 messages.success(request, 'Patch updated')
 
     if is_authenticated(request.user):
-        context['bundles'] = Bundle.objects.filter(owner=request.user)
+        context['bundles'] = request.user.bundles.all()
 
     context['submission'] = patch
     context['patchform'] = form
index 2a2d704679e028a5df905f64a76e19c11a51be04..289a1871aa1a1f2b27d2f3cc920b3fd91c836ceb 100644 (file)
@@ -111,9 +111,8 @@ def profile(request):
     else:
         form = UserProfileForm(instance=request.user.profile)
 
-    # TODO(stephenfin): Add a related_name for User->Bundle
     context = {
-        'bundles': Bundle.objects.filter(owner=request.user),
+        'bundles': request.user.bundles.all(),
         'profileform': form,
     }