From patchwork Thu Apr 12 12:01:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 897629 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40MKJd11tnz9s0x for ; Thu, 12 Apr 2018 22:01:53 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="CTmKlDkm"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40MKJc6Zv4zF1SB for ; Thu, 12 Apr 2018 22:01:52 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="CTmKlDkm"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=23.83.209.75; helo=gorilla.birch.relay.mailchannels.net; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="CTmKlDkm"; dkim-atps=neutral Received: from gorilla.birch.relay.mailchannels.net (gorilla.birch.relay.mailchannels.net [23.83.209.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40MKJW6lC7zF1Rs for ; Thu, 12 Apr 2018 22:01:46 +1000 (AEST) X-Sender-Id: 5xi41l16bi|x-authuser|stephen@that.guru Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 293B63E2B0D for ; Thu, 12 Apr 2018 12:01:40 +0000 (UTC) Received: from one.mxroute.com (unknown [100.96.14.60]) (Authenticated sender: 5xi41l16bi) by relay.mailchannels.net (Postfix) with ESMTPA id 867313E1C50 for ; Thu, 12 Apr 2018 12:01:39 +0000 (UTC) X-Sender-Id: 5xi41l16bi|x-authuser|stephen@that.guru Received: from one.mxroute.com (one-outgoing.mxroute.com [100.96.14.1]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.14.1); Thu, 12 Apr 2018 12:01:40 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: 5xi41l16bi|x-authuser|stephen@that.guru X-MailChannels-Auth-Id: 5xi41l16bi X-Zesty-Bored: 59d1a8907492e78e_1523534499971_139573753 X-MC-Loop-Signature: 1523534499971:1783108131 X-MC-Ingress-Time: 1523534499970 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=7WTA5864TIN/8KaTDUJR+1yEx64KonWU4lLp3UuA7+Q=; b=CTmKlDkmzPZjmmOCFdxafOXkXA oy30yMtzTSQJEaSS0LHPzhVm4iuFXS2jIEje0JrHoaCrz+mKfdil7orcb3idxAu/49Tp8k10NaXTe B48K33kWhCg2tpPIAeAgpDOYlpNTff/C1mayT3KdpWBd4CVwl72Ccqnsn5SmsO8STgmmSaydyiqI3 8Q/fBlobrklZz8vcx1StvkPOgk1ORWOjY/QNlbmvxBtPDHXVKOqwwXTFGfd/HC0pv7QCjTVR84R4Y Djx1lpTfAKZUIr9gd2Mq60S7aRnDYM/sYDVbiyb2wT5Hm4MdFe7MKTLNIwuSL/0EjWH7MAe16VllA wnYlk0HA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH] models: Add a backreference for a user's bundles Date: Thu, 12 Apr 2018 13:01:31 +0100 Message-Id: <20180412120131.16529-1-stephen@that.guru> X-Mailer: git-send-email 2.14.3 X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This is more intuitive. Signed-off-by: Stephen Finucane --- .../migrations/0026_add_user_bundles_backref.py | 22 ++++++++++++++++++++++ patchwork/models.py | 4 +++- patchwork/views/bundle.py | 4 ++-- patchwork/views/patch.py | 2 +- patchwork/views/user.py | 3 +-- 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 patchwork/migrations/0026_add_user_bundles_backref.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 index 00000000..e3dbf805 --- /dev/null +++ b/patchwork/migrations/0026_add_user_bundles_backref.py @@ -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), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index 67c2d3a2..38f0f753 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -781,7 +781,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') diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py index 2d18571d..d795608f 100644 --- a/patchwork/views/bundle.py +++ b/patchwork/views/bundle.py @@ -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 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, diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index 7e962e72..6ff3ef27 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -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 context['submission'] = patch context['patchform'] = form diff --git a/patchwork/views/user.py b/patchwork/views/user.py index 2a2d7046..d6ab4253 100644 --- a/patchwork/views/user.py +++ b/patchwork/views/user.py @@ -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, 'profileform': form, }