Skip to content

Commit

Permalink
Add field to admin (and restrict on User admins)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 4, 2024
1 parent 64b5e72 commit a03630d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from lemarche.tenders.forms import TenderAdminForm
from lemarche.tenders.models import PartnerShareTender, Tender, TenderQuestion, TenderSiae, TenderStepsData
from lemarche.users import constants as user_constants
from lemarche.users.models import User
from lemarche.utils.admin.admin_site import admin_site
from lemarche.utils.fields import ChoiceArrayField, pretty_print_readonly_jsonfield
from lemarche.www.tenders.tasks import restart_send_tender_task
Expand Down Expand Up @@ -190,7 +191,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
ordering = ["-created_at"]

form = TenderForm
autocomplete_fields = ["sectors", "location", "perimeters", "author"]
autocomplete_fields = ["sectors", "location", "perimeters", "author", "admins"]
readonly_fields = [field for field in Tender.READONLY_FIELDS] + [
# slug
# status
Expand Down Expand Up @@ -359,6 +360,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
)
},
),
("Suivi", {"fields": ("admins")}),
(
"Stats",
{
Expand Down Expand Up @@ -414,6 +416,11 @@ def get_readonly_fields(self, request, obj=None):
readonly_fields.append("slug")
return readonly_fields

def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == "admins":
kwargs["queryset"] = User.objects.filter(kind=User.KIND_ADMIN)
return super().formfield_for_manytomany(db_field, request, **kwargs)

def save_model(self, request, obj: Tender, form, change):
"""
Set Tender author on create
Expand Down

0 comments on commit a03630d

Please sign in to comment.