Stack Overflow на русском Asked on December 28, 2021
Как во время изменения формы сформировать уведомление о изменении и отправить его группе?
Есть views
def timetable(request):
timetab = ClassModel.objects.all()
context = {"timetab": timetab}
return render(request, "admin/timetable.html", context)
def revise_timetable(request, pk):
try:
rev_timetable = get_object_or_404(ClassModel, pk=pk)
if request.method == 'POST':
form = ClassModelForm(request.POST, instance=rev_timetable)
if form.is_valid():
post = form.save(commit=False)
post.save()
return HttpResponseRedirect("../../timetable")
else:
form = ClassModelForm(instance=rev_timetable)
return render(request, "admin/revise_timetable.html", {"rev_timetable": rev_timetable, 'form':
form})
except ClassModel.DoesNotExist:
return HttpResponseNotFound("<h2>not found</h2>")
models
class GroupModel(models.Model): # Группа
students = models.ManyToManyField(AdvUser)
teacher = models.ForeignKey(AdvUser, verbose_name='Учитель', on_delete=models.CASCADE,
related_name='groups_teacher', default=None)
course = models.ForeignKey(CourseUser, verbose_name='Курс', on_delete=models.CASCADE,
related_name='groups', default=None)
title = models.CharField('Название', max_length=100, blank=True)
slug = models.SlugField(max_length=100, db_index=True, default=None)
def __str__(self):
return f"{self.title}"
class Meta:
verbose_name = 'Группа'
verbose_name_plural = 'Группы'
class ClassModel(models.Model): # Занятие
groups = models.ForeignKey(GroupModel, verbose_name='Группа', on_delete=models.CASCADE, related_name='classes', default=None, null=True)
classroom = models.ForeignKey('Classroom', on_delete=models.CASCADE, default=None, related_name='classroom', null=True)
date = models.DateTimeField(null=True, verbose_name='Дата проведения занятия',)
theme = models.CharField(max_length=250, verbose_name='Тема', blank=True)
slug = models.SlugField(max_length=100, db_index=True, default=None, null=True)
def __str__(self):
return self.theme
class Meta:
verbose_name = 'Занятие'
verbose_name_plural = 'Занятия'
forms
from django import forms
from manager_school.models import ClassModel
class ClassModelForm(forms.ModelForm):
class Meta:
model = ClassModel
fields = ('classroom', 'date',)
urls
path('timetable/', timetable, name='timetable'),
path('revise_timetable/<int:pk>/', revise_timetable, name='revise_timetable'),
]
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP