Browse Source

Factorisation de code dans formfield_for_foreignkey

SimonBoulier 7 years ago
parent
commit
3a05ba4abb
1 changed files with 2 additions and 5 deletions
  1. 2 5
      coin/offers/admin.py

+ 2 - 5
coin/offers/admin.py

@@ -55,15 +55,12 @@ class OfferSubscriptionAdmin(admin.ModelAdmin):
 
     # Si pas super user on restreint les membres et offres accessibles
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
-        if request.user.is_superuser:
-            return super(OfferSubscriptionAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
-        else:
+        if not request.user.is_superuser:
             if db_field.name == "member":
                 kwargs["queryset"] = Member.objects.manageable_by(request.user)
             if db_field.name == "offer":
-                # pouah c'est pas beau, faut faire mieux, ça serait bien que manageable_by renvoie un QuerrySet plutôt qu'une liste
                 kwargs["queryset"] = Offer.objects.filter(id__in=[p.id for p in Offer.objects.manageable_by(request.user)])
-            return super(OfferSubscriptionAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
+        return super(OfferSubscriptionAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
 
     # Si pas super user on restreint la liste des offres que l'on peut voir
     def get_queryset(self, request):