ValueError Невозможно назначить " - PullRequest
0 голосов
/ 25 апреля 2020
  • также приветствуются любые советы о том, как разработать модель ответа.
  • или даже как лучше структурировать представления
  • Элементы создаются под одним родителем через набор форм

что пытается архивировать

  • unit_price, item_total_price связаны с одним элементом

  • delivery_charges, total_total, промежуточный итог связаны со всеми моделями предметов,

class RfqFullPrice(models.Model):
    sender = models.name = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="quote_sender")`
    receiver = models.name = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="quote_reciever")
    requestedquotation = models.ForeignKey(RequestForQuotation, related_name="replyprice_rfq", on_delete=models.CASCADE) 
    subtotal = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
    delivery_charges = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
    overall_total = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
    validity_start_date = models.DateField()
    validity_end_date = models.DateField()

 class ReplyItemPrice(models.Model):
    full_price = models.ForeignKey(RfqFullPrice, on_delete=models.CASCADE, related_name='full_price')
    the_rfq = models.ForeignKey(RequestForQuotation, on_delete=models.CASCADE)
    item = models.ForeignKey(RequestForQuotationItem, on_delete=models.CASCADE, related_name="rfq_item")
    quantity = models.CharField(max_length = 200, help_text='Enter the qauntity')
    unit_price = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])
    item_total_price = MoneyField(max_digits=14, decimal_places=2, default_currency='USD', validators=[MinMoneyValidator(0)])  

def quote(request, pk):
    template_name = 'request_quote/send_quote.html'
    requestedquotation = get_object_or_404(RequestForQuotation, pk=pk)
    items = RequestForQuotationItem.objects.filter(item=requestedquotation)

if request.method == 'GET':
    full_priceform =QuoteFullPriceForm()
    item_priceform = QuoteItemPriceForm()

elif request.method == 'POST':
    full_priceform =QuoteFullPriceForm(request.POST, request.FILES)
    item_priceform = QuoteItemPriceForm(request.POST, request.FILES)

    if full_priceform.is_valid() and item_priceform.is_valid():
        full_priceform = full_priceform.save(commit=False)
        full_priceform.receiver = requestedquotation.sender
        full_priceform.sender = request.user
        full_priceform.requestedquotation = requestedquotation
        full_priceform.save()

        for form in item_priceform:
            form = item_priceform.save(commit=False)
            form.full_price = full_priceform
            form.the_rfq = requestedquotation
            form.item = items
            form.save()

        messages.success(request, 'Uploaded'\
                                  'successfully')

        return redirect('/')

    else:
        messages.error(request, 'Error While Uploading')     

context = {
    'full_priceform':full_priceform,
    'item_priceform':item_priceform,
    'requestedquotation':requestedquotation,
    'items':items,

}

return render(request, template_name, context)

                            <form class="form-horizontal" method="POST" action="{% url 'rfq:quote' requestedquotation.pk %}" enctype="multipart/form-data">
                                    {% csrf_token %}

                                {% for item in items %}
                                <tr>
                                    <td align="center"><span class="badge badge-primary">#{{ item.pk }}</span></td>
                                    <td align="center">{{ item.name }}</td>
                                    <td align="center">{{ item.discription|safe|linebreaksbr }}</td>
                                    <td align="center"><img src="{% if item.image %} {{ item.image.url }} {% else %} {% static 'img/default.jpg' %} {% endif %}" alt="..." height="150" width="150"></td>
                                    <td align="center">{{ item.quantity }}</td>
                                    <td align="center">{{ item_priceform }}</td>
                                </tr>
                                {% endfor %}
                        </tbody>
                    </table>
                    {{ full_priceform.subtotal }} 
                    {{ full_priceform.delivery_charges }} 
                    {{ full_priceform.overall_total }} 
                    {{ full_priceform.validity_start_date }} 
                    {{ full_priceform.validity_end_date }} 
                    <button type="submit" class="btn btn-success mb-2">Submit</button>
                    </form>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...