Django - save changes made to model objects and render when published

谁都会走 提交于 2019-12-24 19:25:57

问题


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. Teacher's Assistant - Schedules/plans the timetable and courses for the teacher depending on day's agenda
  2. Teacher - approves the items on the agenda and marks if an item on the schedule is completed
  3. Student - views the schedule of an individual teacher

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.

Thanks in advance!

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?


回答1:


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.



来源:https://stackoverflow.com/questions/59254748/django-save-changes-made-to-model-objects-and-render-when-published

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!