A
A
Andrei1penguin12020-11-15 17:47:55
Django
Andrei1penguin1, 2020-11-15 17:47:55

Problem with many-to-many field relationship, how to fix?

Good day, suppose there are two models, one user:

class User(models.Model):
    images = models.ManyToManyField("Image", verbose_name="Фотографии", blank=true)

And another photo itself:
class Image(models.Model):
    image = models.ImageField(verbose_name="Фотография", default="/static/images/default_image.png")

Let's also assume that the addition comes from the admin panel, and here I do not like one thing.
When creating any instance of a model that has a many-to-many field, absolutely all photos related to Image are displayed in this very field, which may not even belong to User
However, those photos, or rather objects that relate to the user, are highlighted in gray, and it seems clear what belongs to the User and what is simply displayed as an Image instance, but this greatly interferes with
How can I remove the display of Image objects in the User.images field, which do not apply to this user
That is, technically everything works, but such an output in the admin panel is very annoying

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexandrBirukov, 2020-11-15
@AlexandrBirukov

use in the admin for the user something like
raw_id_fields = ("images",)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question