ok. send a reply when you are available.

On Wed, May 6, 2020 at 11:13 AM Sergei Sokov <[email protected]> wrote:

> I can a little bit later, ok?
> I think in 2 hour
>
> среда, 6 мая 2020 г., 12:00:13 UTC+2 пользователь Sherif Adigun написал:
>>
>> Please join the meeting now let's quickly fix it .
>>
>> https://us04web.zoom.us/j/77729655336?pwd=c1o2Q0JQOFJiYm5hTlJTYjgra0dOQT09
>>
>> On Monday, May 4, 2020 at 4:37:39 PM UTC+1, Sergei Sokov wrote:
>>>
>>> I have two forms in one template, but one of them doesn't  have data to
>>> my database.
>>> Why does it happen and how to fix it?
>>>
>>> When I fill out the Pack form and press "submit" the terminal shows
>>> that: "POST" /sklad HTTP/1.1" 200 9937
>>> This data doesn't save to my database.
>>>
>>> When I fill out the Sklad form and press "submit" the terminal shows
>>> that: "POST" /sklad HTTP/1.1" 302 0
>>> This data saves to my database fine.
>>>
>>> views.py
>>> class SkladCreateView(LoginRequiredMixin, CustomSuccessMessageMixin,
>>> CreateView):
>>>     model = Sklad
>>>     template_name = 'sklad.html'
>>>     form_class = SkladForm
>>>     success_url = reverse_lazy('sklad')
>>>     success_msg = 'Материал сохранён'
>>>     def get_context_data(self, **kwargs):
>>>         kwargs['sklad_form'] = SkladForm
>>>         kwargs['pack_form'] = PackForm
>>>         kwargs['list_sklad'] = Sklad.objects.all().order_by('material')
>>>         kwargs['list_pack'] = Pack.objects.all().order_by('name_pack')
>>>         return super().get_context_data(**kwargs)
>>>     def form_valid(self, form):
>>>         self.object = form.save(commit=False)
>>>         self.object.author = self.request.user
>>>         self.object.save()
>>>         return super().form_valid(form)
>>>
>>> models.py
>>> class Sklad(models.Model):
>>> author = models.ForeignKey(User, on_delete = models.CASCADE,
>>> verbose_name='автор склада', null=True)
>>> material = models.CharField('название', max_length=200)
>>> unit = models.CharField('единица измерения', max_length=200)
>>> description = models.CharField('описание', max_length=200, null=True)
>>> price_buy = models.IntegerField('цена закупки', )
>>> price_sell = models.IntegerField('цена продажи', )
>>> amount = models.IntegerField('количество', default='0')
>>>
>>> def __str__(self):
>>> return self.material
>>>
>>> class Pack(models.Model):
>>> author = models.ForeignKey(User, on_delete = models.CASCADE,
>>> verbose_name='автор упаковки', null=True)
>>> name_pack = models.CharField('название', max_length=100)
>>> price_pack = models.IntegerField('цена', )
>>>
>>> def __str__(self):
>>> return self.name_pack
>>>
>>>
>>> forms.py
>>> class SkladForm(forms.ModelForm):
>>>     class Meta:
>>>         model = Sklad
>>>         fields = (
>>>             'material',
>>>             'unit',
>>>             'description',
>>>             'price_buy',
>>>             'price_sell',
>>>             'amount',
>>>         )
>>>
>>>     def __init__(self, *args, **kwargs):
>>>         super().__init__(*args, **kwargs)
>>>         for field in self.fields:
>>>             self.fields[field].widget.attrs['class'] = 'form-control'
>>>
>>> class PackForm(forms.ModelForm):
>>>     class Meta:
>>>         model = Pack
>>>         fields = (
>>>             'name_pack',
>>>             'price_pack',
>>>         )
>>>
>>>     def __init__(self, *args, **kwargs):
>>>         super().__init__(*args, **kwargs)
>>>         for field in self.fields:
>>>             self.fields[field].widget.attrs['class'] = 'form-control'
>>>
>>>
>>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/I_32m8lWd-g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/257e308b-91d3-4fa3-8f8f-ca758b72e7e0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/257e308b-91d3-4fa3-8f8f-ca758b72e7e0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACP0aXjvLuR6PAatcY5rmkPs8gzHk5LhrQ%3DnUE174LQU4aP5qg%40mail.gmail.com.

Reply via email to