我有两个模型Permit&Course。
class Permit(models.Model):
name = models.CharField(max_length=50)
skill_course = models.ManyToManyField(Skill, related_name="+", blank=True)
class Course(models.Model):
name = models.CharField(max_length=50)
skills = models.ManyToManyField(Skill, related_name="courses",blank=True,)
students = models.ManyToManyField(User, related_name="courses",blank=True,)
单击许可对象将显示动态获取许可的学生(在带有 GET 方法的更新视图中(。
如何与这些学生一起创建课程?(在带有 POST 方法的创建视图中(
我必须在 2 个视图之间传递数据吗?我想创建一个 utils.py 文件,在那里创建一个方法,其中包含我将在其他方法或类中重用的数据,但是该类或函数将具有request
和pk
,我不知道如何返回字典,因为它应该有请求和模板对吗?我被困在了这里,真的很感谢任何帮助,提前感谢......
首先,您应该在setting.py
中激活会话中间件。
然后使用类似这样的东西:
def update_project_filter(request):
...
selected_project_id = project_form.cleaned_data["Project_Name"].id
request.session['selected_project_id'] = selected_project_id
...
def update_project(request):
...
selected_project_id = request.session.get('selected_project_id')
...def update_project_filter(request):
...
selected_project_id = project_form.cleaned_data["Project_Name"].id
request.session['selected_project_id'] = selected_project_id
...
def update_project(request):
...
selected_project_id = request.session.get('selected_project_id')
...