My model.py is this.
class Country(models.Model):
country_name = models.CharField(max_length=200)
country_fact = models.CharField(max_length=1000)
country_capital = models.CharField(max_length=100)
country_flags = models.ImageField(upload_to='flags')
View.py is this
def index(request):
country = Country.objects.all()
return render(request,'index.html',{'country':country})
I'm retrieving those data in HTML by using this
{% for count in country %}
<img src="{{ count.country_flags.url }}">
This retrieves all the country images from the database(I'm using Postgresql). I want to retrieve only one random country flag from the database. How can I achieve this? Thanks for the help.