Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

python - 修改Django管理页面中的auth_users和自定义相关模型的queryset(modifying queryset in django admin page for auth_users and a custom related model)

So, I have a model DailyTask that has a OneToOneField to the auth_users model, this is the DailyTask model fields :

(所以,我有一个模型DailyTask具有OneToOneField到auth_users模型,这是DailyTask模型字段:)

task_id

(task_id)

task_date

(task_date)

user ( OneToOneField )

(用户(OneToOneField))

Now each user has to submit a new Task report daily, already have an AdminModel that display all the submitted Tasks respectively to the logged in non superuser , here is the AdminModel :

(现在,每个user必须提交新的Task每日报告,已经有一个AdminModel是显示所有提交的Tasks分别向非登录superuser ,这里是AdminModel :)

class DailyTaskAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(user=request.user)

and I have created a proxy Model so I can create and register another AdminModel using the same Model :

(并且我已经创建了一个proxy Model因此我可以使用相同的模型创建并注册另一个AdminModel :)

class MyDailyTask(DailyTask):
    class Meta:
        proxy = True

then the second AdminModel :

(然后是第二个AdminModel:)

class DailyPresenceAdmin(DailyTaskAdmin):
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter()

admin.site.register(MyDailyTask, DailyPresenceAdmin)

My only problem is, that in the DailyPresenceAdmin AdminModel, want to list all the users from auth_users that has not uploaded their Task of the day yet.

(我唯一的问题是,在DailyPresenceAdmin AdminModel中,要列出auth_users中尚未上传其Task of the day所有users 。)

so it will be something like,

(所以会是这样,)

if auth_users.user has no TaskID with the date equals to today's date in the DailyTask Model yet, then I want to take the user and list it in the DailyPresenceAdmin AdminModel.

(如果auth_users.user在DateTask模型中还没有日期等于今天的日期的TaskID,那么我想接收该用户并将其列出在DailyPresenceAdmin AdminModel中。)

  ask by DaveMann translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...