Django-保存对模型对象所做的更改并在发布时进行渲染 [英] Django - save changes made to model objects and render when published

查看:88
本文介绍了Django-保存对模型对象所做的更改并在发布时进行渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django的新手,正在Django中从事我的第一个项目。我为我的应用程序提供了一个更简单的示例,其中-
我有3种不同类型的应用程序用户。

I am new to Django and working on my first project in Django. I am providing a simpler example for my application where - I have 3 different types of users for the application.


  1. 教师助手-根据当天的日程安排/计划教师的时间表和课程

  2. 老师-批准日程中的项目并标记日程中的项目是否完成

  3. 学生-查看一位教师的时间表

当前,我已经准备好了整个应用程序及其所有功能,助手会根据老师的课程和课程表为他创建时间表/时间表(即添加/编辑/删除属于主题的各种模型对象)。

Currently, I have this whole application ready with all its functionalities, where the assistant would create a timetable/schedule (ie., add/edit/delete various model objects which are subjects) for the teacher depending upon her courses and agenda for the class.

当前,当助手对日程表进行更改(例如删除或编辑现有模型对象)时,这些更改将直接更新模型对象。

Currently, when the assistant, makes changes to the schedule (such as deletes, or edits an existing model object) these changes directly update the model object.

我要实现的是,只有当助手发布时间表后,老师才能批准并且学生应该可以查看时间表,并且助手应该拥有自己的版本他可以对其进行更改和编辑的时间表(除非已发布,否则其他两个角色不应查看这些更改和编辑)。
当前,助手所做的所有更改都将在模型对象中直接更新,并且这些更改将呈现在教师和学生的页面上。我只有一个模型类来存储有关预定项目的信息。

What I would want to achieve is that, only when the Assistant publishes the schedule, the teacher can approve and students should be able to view it, and the assistant should have his own version of the schedule where he can make changes and edits to it (These changes and edits should not be viewed by other two roles unless they are published). Currently, all the changes made by the Assistant are directly updated in the model objects and the same are rendered onto the pages of the Teacher and Student. I have only one model class for storing the information about the item being scheduled.

我该如何设计?任何建议/文档或代码段都将真正有帮助。

How can I design this? Any suggestions/documentation or piece of code would really help.

预先感谢!

编辑1:
我想到的唯一解决方案是,当Assistant按下发布按钮,存储模型对象的副本并将该副本呈现到其他用户的页面上时?但是,我该如何在Django中编写呢?

Edit 1 : The only solution comes to my mind is when the Assistant hits the publish button, storing a copy of the model objects and rendering this copy onto the pages of other users? But how do I write this in Django?

推荐答案

在模型中添加两​​个额外的变量(created_at和publish_flag)。在视图中,您将发送publish_tag = true和最新的created_at。

Add two extra variables (created_at and publish_flag) in the model. In view you will send the publish_tag=true and most recent created_at.

这篇关于Django-保存对模型对象所做的更改并在发布时进行渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆