Answer the question
In order to leave comments, you need to log in
How to implement BooleanField change on form save in Django?
class Zakaz(models.Model):
pokupatel_name = models.CharField(max_length=150, verbose_name= 'Покупатель')
pokupatel_email = models.EmailField(verbose_name= 'Покупатель email')
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$',message=
"Phone number must be entered in the format: '+999999999'. Up to 10 digits allowed.")
pokupatel_phone = models.CharField(validators=[phone_regex], max_length=12, verbose_name= 'Телефон покупателя') # validators should be a list
work = ForeignKey(Usluga, on_delete=PROTECT, verbose_name= 'Вид работы', related_name="work")
date = DateTimeField(auto_now_add=True,verbose_name= 'Дата оформления заказа')
v_rabote = models.BooleanField(default=False, verbose_name= 'Заказ в работе')
def __str__(self) :
return "Заказ №" + str(self.id) + " - " + str(self.work)
class Meta:
verbose_name= 'Заказ'
verbose_name_plural= 'Заказы'
class NaRabotu(Instrument,Material):
objects = NaRabotuManager()#Забирает только отсортированные Менеджером объекты!!!
zakaz = OneToOneField (Zakaz, on_delete=PROTECT, db_index=True, verbose_name= 'Заказ',related_name="zakaz")
rabotnik = ForeignKey(Rabotnik, on_delete=PROTECT, verbose_name= 'Работник', related_name="rabotnik")
date = DateTimeField(auto_now_add=True,verbose_name= 'Принято к исполнению')
def __str__(self):
return str(self.zakaz)
class Meta:
verbose_name= 'В работе'
verbose_name_plural= 'В работе'
ordering = ['-date']
class ZakazAddView(CreateView):
template_name = 'rabota/add_zakaz.html'
model = Zakaz
fields =('pokupatel_name','pokupatel_email', 'pokupatel_phone', 'work')
success_url = reverse_lazy ('rabota:index')
#Обработка формы в работу:
class RabotaAddView(CreateView):
template_name = 'rabota/add_rabota.html'
form_class = NaRabotuForm
success_url = reverse_lazy ('rabota:index')
Answer the question
In order to leave comments, you need to log in
Add Method to WorkAddView
def form_valid(self, form):
response = super().form_valid(form)
Zakaz.objects.filter(id=self.object.zakaz_id).update(v_rabote=True)
return response
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question