Merge pull request #524 from taigaio/fixing-admin-errors-and-making-it-usable-again
Fixing admin errors and making it usable againremotes/origin/logger
commit
9821d2ec8f
|
@ -17,8 +17,8 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from taiga.projects.milestones.admin import MilestoneInline
|
from taiga.projects.milestones.admin import MilestoneInline
|
||||||
from taiga.projects.notifications.admin import WatchedInline
|
from taiga.projects.notifications.admin import NotifyPolicyInline
|
||||||
from taiga.projects.votes.admin import VoteInline
|
from taiga.projects.likes.admin import LikeInline
|
||||||
from taiga.users.admin import RoleInline
|
from taiga.users.admin import RoleInline
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
@ -26,19 +26,49 @@ from . import models
|
||||||
class MembershipAdmin(admin.ModelAdmin):
|
class MembershipAdmin(admin.ModelAdmin):
|
||||||
list_display = ['project', 'role', 'user']
|
list_display = ['project', 'role', 'user']
|
||||||
list_display_links = list_display
|
list_display_links = list_display
|
||||||
list_filter = ['project', 'role']
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
def get_object(self, *args, **kwargs):
|
||||||
|
self.obj = super().get_object(*args, **kwargs)
|
||||||
|
return self.obj
|
||||||
|
|
||||||
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
|
if db_field.name in ["user", "invited_by"] and getattr(self, 'obj', None):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
memberships__project=self.obj.project)
|
||||||
|
|
||||||
|
elif db_field.name in ["role"] and getattr(self, 'obj', None):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
project=self.obj.project)
|
||||||
|
|
||||||
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
class MembershipInline(admin.TabularInline):
|
class MembershipInline(admin.TabularInline):
|
||||||
model = models.Membership
|
model = models.Membership
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
def get_formset(self, request, obj=None, **kwargs):
|
||||||
|
# Hack! Hook parent obj just in time to use in formfield_for_manytomany
|
||||||
|
self.parent_obj = obj
|
||||||
|
return super(MembershipInline, self).get_formset(request, obj, **kwargs)
|
||||||
|
|
||||||
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
|
if (db_field.name in ["user", "invited_by"]):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
memberships__project=self.parent_obj)
|
||||||
|
|
||||||
|
elif (db_field.name in ["role"]):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
project=self.parent_obj)
|
||||||
|
|
||||||
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ProjectAdmin(admin.ModelAdmin):
|
class ProjectAdmin(admin.ModelAdmin):
|
||||||
list_display = ["name", "owner", "created_date", "total_milestones",
|
list_display = ["name", "owner", "created_date", "total_milestones",
|
||||||
"total_story_points"]
|
"total_story_points"]
|
||||||
list_display_links = list_display
|
list_display_links = list_display
|
||||||
inlines = [RoleInline, MembershipInline, MilestoneInline, WatchedInline, VoteInline]
|
inlines = [RoleInline, MembershipInline, MilestoneInline, NotifyPolicyInline, LikeInline]
|
||||||
|
|
||||||
def get_object(self, *args, **kwargs):
|
def get_object(self, *args, **kwargs):
|
||||||
self.obj = super().get_object(*args, **kwargs)
|
self.obj = super().get_object(*args, **kwargs)
|
||||||
|
@ -49,10 +79,16 @@ class ProjectAdmin(admin.ModelAdmin):
|
||||||
"default_priority", "default_severity",
|
"default_priority", "default_severity",
|
||||||
"default_issue_status", "default_issue_type"]):
|
"default_issue_status", "default_issue_type"]):
|
||||||
if getattr(self, 'obj', None):
|
if getattr(self, 'obj', None):
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.filter(
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
project=self.obj)
|
project=self.obj)
|
||||||
else:
|
else:
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.none()
|
kwargs["queryset"] = db_field.related.model.objects.none()
|
||||||
|
|
||||||
|
elif (db_field.name in ["owner"]
|
||||||
|
and getattr(self, 'obj', None)):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
memberships__project=self.obj.project)
|
||||||
|
|
||||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
||||||
|
@ -68,13 +104,13 @@ class ProjectAdmin(admin.ModelAdmin):
|
||||||
class PointsAdmin(admin.ModelAdmin):
|
class PointsAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "order", "name", "value"]
|
list_display = ["project", "order", "name", "value"]
|
||||||
list_display_links = ["name"]
|
list_display_links = ["name"]
|
||||||
list_filter = ["project"]
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
class UserStoryStatusAdmin(admin.ModelAdmin):
|
class UserStoryStatusAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "order", "name", "is_closed"]
|
list_display = ["project", "order", "name", "is_closed"]
|
||||||
list_display_links = ["name"]
|
list_display_links = ["name"]
|
||||||
list_filter = ["project"]
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
# Tasks common admins
|
# Tasks common admins
|
||||||
|
@ -82,7 +118,7 @@ class UserStoryStatusAdmin(admin.ModelAdmin):
|
||||||
class TaskStatusAdmin(admin.ModelAdmin):
|
class TaskStatusAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "order", "name", "is_closed", "color"]
|
list_display = ["project", "order", "name", "is_closed", "color"]
|
||||||
list_display_links = ["name"]
|
list_display_links = ["name"]
|
||||||
list_filter = ["project"]
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
# Issues common admins
|
# Issues common admins
|
||||||
|
@ -90,25 +126,26 @@ class TaskStatusAdmin(admin.ModelAdmin):
|
||||||
class SeverityAdmin(admin.ModelAdmin):
|
class SeverityAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "order", "name", "color"]
|
list_display = ["project", "order", "name", "color"]
|
||||||
list_display_links = ["name"]
|
list_display_links = ["name"]
|
||||||
list_filter = ["project"]
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
class PriorityAdmin(admin.ModelAdmin):
|
class PriorityAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "order", "name", "color"]
|
list_display = ["project", "order", "name", "color"]
|
||||||
list_display_links = ["name"]
|
list_display_links = ["name"]
|
||||||
list_filter = ["project"]
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
class IssueTypeAdmin(admin.ModelAdmin):
|
class IssueTypeAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "order", "name", "color"]
|
list_display = ["project", "order", "name", "color"]
|
||||||
list_display_links = ["name"]
|
list_display_links = ["name"]
|
||||||
list_filter = ["project"]
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
class IssueStatusAdmin(admin.ModelAdmin):
|
class IssueStatusAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "order", "name", "is_closed", "color"]
|
list_display = ["project", "order", "name", "is_closed", "color"]
|
||||||
list_display_links = ["name"]
|
list_display_links = ["name"]
|
||||||
list_filter = ["project"]
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
class ProjectTemplateAdmin(admin.ModelAdmin):
|
class ProjectTemplateAdmin(admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -23,7 +23,18 @@ from . import models
|
||||||
class AttachmentAdmin(admin.ModelAdmin):
|
class AttachmentAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "project", "attached_file", "owner", "content_type", "content_object"]
|
list_display = ["id", "project", "attached_file", "owner", "content_type", "content_object"]
|
||||||
list_display_links = ["id", "attached_file",]
|
list_display_links = ["id", "attached_file",]
|
||||||
list_filter = ["project", "content_type"]
|
search_fields = ["id", "attached_file", "project__name", "project__slug"]
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
def get_object(self, *args, **kwargs):
|
||||||
|
self.obj = super().get_object(*args, **kwargs)
|
||||||
|
return self.obj
|
||||||
|
|
||||||
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
|
if (db_field.name in ["owner"]and getattr(self, 'obj', None)):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
memberships__project=self.obj.project)
|
||||||
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class AttachmentInline(generic.GenericTabularInline):
|
class AttachmentInline(generic.GenericTabularInline):
|
||||||
|
|
|
@ -19,14 +19,12 @@ from django.contrib import admin
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
|
||||||
|
class BaseCustomAttributeAdmin:
|
||||||
@admin.register(models.UserStoryCustomAttribute)
|
list_display = ["id", "name", "type", "project", "order"]
|
||||||
class UserStoryCustomAttributeAdmin(admin.ModelAdmin):
|
|
||||||
list_display = ["id", "name", "project", "order"]
|
|
||||||
list_display_links = ["id", "name"]
|
list_display_links = ["id", "name"]
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
"fields": ("name", "description", ("project", "order"))
|
"fields": ("name", "type", "description", ("project", "order"))
|
||||||
}),
|
}),
|
||||||
("Advanced options", {
|
("Advanced options", {
|
||||||
"classes": ("collapse",),
|
"classes": ("collapse",),
|
||||||
|
@ -35,37 +33,19 @@ class UserStoryCustomAttributeAdmin(admin.ModelAdmin):
|
||||||
)
|
)
|
||||||
readonly_fields = ("created_date", "modified_date")
|
readonly_fields = ("created_date", "modified_date")
|
||||||
search_fields = ["id", "name", "project__name", "project__slug"]
|
search_fields = ["id", "name", "project__name", "project__slug"]
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.UserStoryCustomAttribute)
|
||||||
|
class UserStoryCustomAttributeAdmin(BaseCustomAttributeAdmin, admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.TaskCustomAttribute)
|
@admin.register(models.TaskCustomAttribute)
|
||||||
class TaskCustomAttributeAdmin(admin.ModelAdmin):
|
class TaskCustomAttributeAdmin(BaseCustomAttributeAdmin, admin.ModelAdmin):
|
||||||
list_display = ["id", "name", "project", "order"]
|
pass
|
||||||
list_display_links = ["id", "name"]
|
|
||||||
fieldsets = (
|
|
||||||
(None, {
|
|
||||||
"fields": ("name", "description", ("project", "order"))
|
|
||||||
}),
|
|
||||||
("Advanced options", {
|
|
||||||
"classes": ("collapse",),
|
|
||||||
"fields": (("created_date", "modified_date"),)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
readonly_fields = ("created_date", "modified_date")
|
|
||||||
search_fields = ["id", "name", "project__name", "project__slug"]
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.IssueCustomAttribute)
|
@admin.register(models.IssueCustomAttribute)
|
||||||
class IssueCustomAttributeAdmin(admin.ModelAdmin):
|
class IssueCustomAttributeAdmin(BaseCustomAttributeAdmin, admin.ModelAdmin):
|
||||||
list_display = ["id", "name", "project", "order"]
|
pass
|
||||||
list_display_links = ["id", "name"]
|
|
||||||
fieldsets = (
|
|
||||||
(None, {
|
|
||||||
"fields": ("name", "description", ("project", "order"))
|
|
||||||
}),
|
|
||||||
("Advanced options", {
|
|
||||||
"classes": ("collapse",),
|
|
||||||
"fields": (("created_date", "modified_date"),)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
readonly_fields = ("created_date", "modified_date")
|
|
||||||
search_fields = ["id", "name", "project__name", "project__slug"]
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ class IssueAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "milestone", "ref", "subject",]
|
list_display = ["project", "milestone", "ref", "subject",]
|
||||||
list_display_links = ["ref", "subject",]
|
list_display_links = ["ref", "subject",]
|
||||||
inlines = [WatchedInline, VoteInline]
|
inlines = [WatchedInline, VoteInline]
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
search_fields = ["subject", "description", "id", "ref"]
|
||||||
|
|
||||||
def get_object(self, *args, **kwargs):
|
def get_object(self, *args, **kwargs):
|
||||||
self.obj = super().get_object(*args, **kwargs)
|
self.obj = super().get_object(*args, **kwargs)
|
||||||
|
@ -35,11 +37,11 @@ class IssueAdmin(admin.ModelAdmin):
|
||||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
if (db_field.name in ["status", "priority", "severity", "type", "milestone"]
|
if (db_field.name in ["status", "priority", "severity", "type", "milestone"]
|
||||||
and getattr(self, 'obj', None)):
|
and getattr(self, 'obj', None)):
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.filter(
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
project=self.obj.project)
|
project=self.obj.project)
|
||||||
elif (db_field.name in ["owner", "assigned_to"]
|
elif (db_field.name in ["owner", "assigned_to"]
|
||||||
and getattr(self, 'obj', None)):
|
and getattr(self, 'obj', None)):
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.filter(
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
memberships__project=self.obj.project)
|
memberships__project=self.obj.project)
|
||||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -23,3 +23,4 @@ from . import models
|
||||||
class LikeInline(GenericTabularInline):
|
class LikeInline(GenericTabularInline):
|
||||||
model = models.Like
|
model = models.Like
|
||||||
extra = 0
|
extra = 0
|
||||||
|
raw_id_fields = ["user"]
|
||||||
|
|
|
@ -25,14 +25,27 @@ class MilestoneInline(admin.TabularInline):
|
||||||
model = models.Milestone
|
model = models.Milestone
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
def get_formset(self, request, obj=None, **kwargs):
|
||||||
|
# Hack! Hook parent obj just in time to use in formfield_for_manytomany
|
||||||
|
self.parent_obj = obj
|
||||||
|
return super(MilestoneInline, self).get_formset(request, obj, **kwargs)
|
||||||
|
|
||||||
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
|
if (db_field.name in ["owner"]):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
memberships__project=self.parent_obj)
|
||||||
|
|
||||||
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class MilestoneAdmin(admin.ModelAdmin):
|
class MilestoneAdmin(admin.ModelAdmin):
|
||||||
list_display = ["name", "project", "owner", "closed", "estimated_start",
|
list_display = ["name", "project", "owner", "closed", "estimated_start",
|
||||||
"estimated_finish"]
|
"estimated_finish"]
|
||||||
list_display_links = list_display
|
list_display_links = list_display
|
||||||
list_filter = ["project"]
|
|
||||||
readonly_fields = ["owner"]
|
readonly_fields = ["owner"]
|
||||||
inlines = [WatchedInline, VoteInline]
|
inlines = [WatchedInline, VoteInline]
|
||||||
|
search_fields = ["name", "id"]
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(models.Milestone, MilestoneAdmin)
|
admin.site.register(models.Milestone, MilestoneAdmin)
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.contenttypes.admin import GenericTabularInline
|
from django.contrib.contenttypes.admin import GenericTabularInline
|
||||||
|
from django.contrib.admin import TabularInline
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
@ -23,3 +24,10 @@ from . import models
|
||||||
class WatchedInline(GenericTabularInline):
|
class WatchedInline(GenericTabularInline):
|
||||||
model = models.Watched
|
model = models.Watched
|
||||||
extra = 0
|
extra = 0
|
||||||
|
raw_id_fields = ["project", "user"]
|
||||||
|
|
||||||
|
class NotifyPolicyInline(TabularInline):
|
||||||
|
model = models.NotifyPolicy
|
||||||
|
extra = 0
|
||||||
|
readonly_fields = ("notify_level",)
|
||||||
|
raw_id_fields = ["user"]
|
||||||
|
|
|
@ -24,10 +24,11 @@ from . import models
|
||||||
|
|
||||||
|
|
||||||
class TaskAdmin(admin.ModelAdmin):
|
class TaskAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "milestone", "user_story", "ref", "subject",]
|
list_display = ["project", "milestone", "user_story", "ref", "subject",]
|
||||||
list_display_links = ["ref", "subject",]
|
list_display_links = ["ref", "subject",]
|
||||||
list_filter = ["project"]
|
|
||||||
inlines = [WatchedInline, VoteInline]
|
inlines = [WatchedInline, VoteInline]
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
search_fields = ["subject", "description", "id", "ref"]
|
||||||
|
|
||||||
def get_object(self, *args, **kwargs):
|
def get_object(self, *args, **kwargs):
|
||||||
self.obj = super().get_object(*args, **kwargs)
|
self.obj = super().get_object(*args, **kwargs)
|
||||||
|
@ -36,11 +37,11 @@ class TaskAdmin(admin.ModelAdmin):
|
||||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
if (db_field.name in ["status", "milestone", "user_story"]
|
if (db_field.name in ["status", "milestone", "user_story"]
|
||||||
and getattr(self, 'obj', None)):
|
and getattr(self, 'obj', None)):
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.filter(
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
project=self.obj.project)
|
project=self.obj.project)
|
||||||
elif (db_field.name in ["owner", "assigned_to"]
|
elif (db_field.name in ["owner", "assigned_to"]
|
||||||
and getattr(self, 'obj', None)):
|
and getattr(self, 'obj', None)):
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.filter(
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
memberships__project=self.obj.project)
|
memberships__project=self.obj.project)
|
||||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -35,28 +35,28 @@ class RolePointsInline(admin.TabularInline):
|
||||||
class RolePointsAdmin(admin.ModelAdmin):
|
class RolePointsAdmin(admin.ModelAdmin):
|
||||||
list_display = ["user_story", "role", "points"]
|
list_display = ["user_story", "role", "points"]
|
||||||
list_display_links = list_display
|
list_display_links = list_display
|
||||||
list_filter = ["role", "user_story__project"]
|
|
||||||
readonly_fields = ["user_story", "role", "points"]
|
readonly_fields = ["user_story", "role", "points"]
|
||||||
|
|
||||||
|
|
||||||
class UserStoryAdmin(admin.ModelAdmin):
|
class UserStoryAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "milestone", "ref", "subject",]
|
list_display = ["project", "milestone", "ref", "subject",]
|
||||||
list_display_links = ["ref", "subject",]
|
list_display_links = ["ref", "subject",]
|
||||||
list_filter = ["project"]
|
|
||||||
inlines = [RolePointsInline, WatchedInline, VoteInline]
|
inlines = [RolePointsInline, WatchedInline, VoteInline]
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
search_fields = ["subject", "description", "id", "ref"]
|
||||||
|
|
||||||
def get_object(self, *args, **kwargs):
|
def get_object(self, *args, **kwargs):
|
||||||
self.obj = super().get_object(*args, **kwargs)
|
self.obj = super().get_object(*args, **kwargs)
|
||||||
return self.obj
|
return self.obj
|
||||||
|
|
||||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
if (db_field.name in ["status", "milestone"]
|
if (db_field.name in ["status", "milestone", "generated_from_issue"]
|
||||||
and getattr(self, 'obj', None)):
|
and getattr(self, 'obj', None)):
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.filter(
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
project=self.obj.project)
|
project=self.obj.project)
|
||||||
elif (db_field.name in ["owner", "assigned_to"]
|
elif (db_field.name in ["owner", "assigned_to"]
|
||||||
and getattr(self, 'obj', None)):
|
and getattr(self, 'obj', None)):
|
||||||
kwargs["queryset"] = db_field.related.parent_model.objects.filter(
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
memberships__project=self.obj.project)
|
memberships__project=self.obj.project)
|
||||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -23,3 +23,4 @@ from . import models
|
||||||
class VoteInline(GenericTabularInline):
|
class VoteInline(GenericTabularInline):
|
||||||
model = models.Vote
|
model = models.Vote
|
||||||
extra = 0
|
extra = 0
|
||||||
|
raw_id_fields = ["user"]
|
||||||
|
|
|
@ -28,11 +28,23 @@ class WikiPageAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "slug", "owner"]
|
list_display = ["project", "slug", "owner"]
|
||||||
list_display_links = list_display
|
list_display_links = list_display
|
||||||
inlines = [WatchedInline, VoteInline]
|
inlines = [WatchedInline, VoteInline]
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
|
def get_object(self, *args, **kwargs):
|
||||||
|
self.obj = super().get_object(*args, **kwargs)
|
||||||
|
return self.obj
|
||||||
|
|
||||||
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||||
|
if (db_field.name in ["owner", "last_modifier"] and getattr(self, 'obj', None)):
|
||||||
|
kwargs["queryset"] = db_field.related.model.objects.filter(
|
||||||
|
memberships__project=self.obj.project)
|
||||||
|
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||||
|
|
||||||
admin.site.register(models.WikiPage, WikiPageAdmin)
|
admin.site.register(models.WikiPage, WikiPageAdmin)
|
||||||
|
|
||||||
class WikiLinkAdmin(admin.ModelAdmin):
|
class WikiLinkAdmin(admin.ModelAdmin):
|
||||||
list_display = ["project", "title"]
|
list_display = ["project", "title"]
|
||||||
list_display_links = list_display
|
list_display_links = list_display
|
||||||
|
raw_id_fields = ["project"]
|
||||||
|
|
||||||
admin.site.register(models.WikiLink, WikiLinkAdmin)
|
admin.site.register(models.WikiLink, WikiLinkAdmin)
|
||||||
|
|
Loading…
Reference in New Issue