Я добавил для l oop к моему html после того, как добавил больше данных в Queryset. По какой-то причине он показывает 1 из 3 значений, которые я передал. - Я мог бы их распечатать, он просто не отображается на html.
Страница результатов - имя_клиента (синим цветом), отсутствующее имя_продукта + время ожидания (красным)
Есть идеи? спасибо
models.py
class Orders(models.Model):
created_date = models.DateTimeField(auto_now_add=True)
client_id = models.IntegerField()
client_name = models.CharField(max_length=50, blank=True, null=True)
delivery_city = models.CharField(max_length=50, blank=True, null=True)
delivery_address = models.CharField(max_length=50, blank=True, null=True)
product_id = models.IntegerField()
sold_by = models.CharField(max_length=20)
sale_type = models.CharField(max_length=20, blank=True, null=True)
units_to_buy = models.IntegerField(blank=True, null=True)
order_cost = models.DecimalField(decimal_places=2, max_digits=100000, blank=True, null=True)
payment_method = models.CharField(max_length=20, blank=True, null=True)
payment_channel = models.CharField(max_length=20, blank=True, null=True)
invoice = models.CharField(max_length=20, blank=True, null=True)
delivery_cost = models.DecimalField(decimal_places=2, max_digits=100000, blank=True, null=True)
delivery_type = models.CharField(max_length=20, blank=True, null=True)
delivery_status = models.CharField(max_length=20, default='ממתין למשלוח')
delivery_person_name = models.CharField(max_length=20, blank=True, null=True)
notes = models.TextField(blank=True, null=True)
modified_date = models.DateTimeField(auto_now=True)
def __str__(self):
return '{}'.format(self.client_name + ' - (' + self.sold_by + ')')
class Clients(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20, blank=True, null=True)
client_type = models.CharField(max_length=15, blank=True, null=True)
company_name = models.CharField(max_length=30, blank=True, null=True)
address = models.CharField(max_length=30, blank=True, null=True)
city = models.CharField(max_length=15, blank=True, null=True)
phone_number = models.CharField(max_length=10)
additional_phone_number = models.CharField(max_length=10, blank=True, null=True)
email = models.EmailField(max_length=30, blank=True, null=True)
card_type = models.CharField(max_length=15, blank=True, null=True)
four_digits = models.IntegerField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)
added = models.DateTimeField(auto_now=True)
created = models.DateTimeField(auto_now=True)
def __str__(self):
return '{}'.format(self.first_name)
class Products(models.Model):
product_name = models.CharField(max_length=50, verbose_name=u'שם המוצר')
supplier_name = models.CharField(max_length=20, blank=True, null=True)
purchase_price = models.DecimalField(decimal_places=2, max_digits=100000, blank=True, null=True)
purchase_price_before_fees = models.DecimalField(decimal_places=2, max_digits=100000, blank=True, null=True)
final_price = models.DecimalField(decimal_places=2, max_digits=100000, blank=True, null=True)
final_price_before_fees = models.DecimalField(decimal_places=2, max_digits=100000, blank=True, null=True)
inventory_in = models.IntegerField(blank=True, null=True)
inventory_out = models.IntegerField(blank=True, null=True)
inventory_total = models.IntegerField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)
created = models.DateTimeField(auto_now=True)
def __str__(self):
return '{}'.format(self.product_name)
URLs.py
...
path('orders/', views.orders_filter_view, name='orders'),
...
Views.py
def orders_filter_view(request):
qs = models.Orders.objects.all()
...
for order in qs:
client = models.Clients.objects.get(pk=order.client_id)
client_name = client.first_name
qs.client_name = client_name <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
product = models.Products.objects.get(pk=order.product_id)
product_name = product.product_name
qs.product_name = product_name <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
tz_info = order.created_date.tzinfo
qs.waiting_time = order.created_date - datetime.datetime.now(tz_info) <<<<<<<<<<<<<<<<<<<<<<<
total_matches = qs.count()
context = {
'orders': qs, <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'view': 'הזמנות',
'total_matches': total_matches,
'titles': orders_titles
}
return render(request, 'adolim/orders.html', context)
Заказы. html
{% for order in orders %}
<tr>
<td class="center">{{ order.client_name }}</td> <<<<<<<<<<<<<<<<<<<<<<<<
<td class="center">{{ order.product_name }}</td> <<<<<<<<<<<<<<<<<<<<<<<<
...
<td class="center">{{ order.delivery_person_name }}</td>
{% if order.delivery_status == 'סופק' %}
<td class="center green-text">{{ order.delivery_status }}</td>
{% else %}
<td class="center">{{ order.delivery_status }}</td>
{% endif %}
<td class="center yellow-text">{{ order.waiting_time }}</td> <<<<<<<<<<<<<<<<<
Страница результатов - имя_клиента (синим цветом), отсутствующее имя_продукта + время ожидания (красным)