T
T
tank0072019-11-21 13:26:55
Django
tank007, 2019-11-21 13:26:55

How to create a link to a specific model element?

Good afternoon.
Please tell me the best way to do it.
There is a model, it has a field with the ForeignKey type.

class ProductsInOrder(models.Model):
    product = models.ForeignKey(Products, on_delete=models.CASCADE, verbose_name='Товар')
    price   = models.CharField(max_length=20, default='', blank=True, verbose_name='Цена')
    order   = models.ForeignKey(Orders, on_delete=models.CASCADE, verbose_name='Заказ')

The Products model referenced by this field has a large number of elements.
class Orders(models.Model):
    name    = models.CharField(max_length=40, blank=True)
    town    = models.CharField(max_length=80, blank=True)
    tel     = models.CharField(max_length=50)

And when, after writing the Order model, I try to open this element, it opens for 2 minutes, loads all the elements from Products and forms a list.
How to make it so that the list is not formed, but a link to a specific element is indicated in the product field?
I open the model element through the admin panel, using inlines.
I thought to write the id in this field, and then at the moment of opening the Order model, get the desired element. But even I can’t figure out how to do it, so that later you can follow the link.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_, 2019-11-21
@tank007

If you are talking about the admin panel - use raw_id_field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question