I have a model having image and reference field (reference is a string value). I need to filter the images list by reference, and a reference can have multiple images.
Now I'm wishing a dropdown menu having reference field values. How can I do that.
Here is the model
class AllImg(models.Model):
ref_by = models.CharField(max_length=100)
img_name = models.ImageField(upload_to='uploads/allimg/')
now in my view of showing the list of AllImg model i have to filter them by ref_by field. I'll set the value of the ref_by in session and show the list according to that value. And if nothing is set in that session key, all entries of AllImg model will be shown.
Try this:
ALLImg.objects.all().values('ref_by', 'img_name')