[#3265] ajout candidature : limiter les offres d'emploi à la région du user
authorPA Parent <paparent@paparent.me>
Fri, 8 Jun 2012 17:46:36 +0000 (13:46 -0400)
committerPA Parent <paparent@paparent.me>
Fri, 8 Jun 2012 17:46:36 +0000 (13:46 -0400)
project/recrutement/admin.py

index 2365596..56c4c27 100644 (file)
@@ -496,6 +496,13 @@ class CandidatAdmin(BaseAdmin, VersionAdmin, ExportAdmin):
             return True
         return False
 
+    def formfield_for_foreignkey(self, db_field, request, **kwargs):
+        if db_field.name == 'offre_emploi':
+            employe = get_emp(request.user)
+            kwargs["queryset"] = OffreEmploi.objects.filter(region=employe.implantation.region)
+            return db_field.formfield(**kwargs)
+        return super(CandidatAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
+
     def get_changelist(self, request, **kwargs):
         return OrderedChangeList