Hi, am building a blog and the model consist of 14 stations. I see it as unprofessional to create a template for each of this station. Is there a way i can do so that in my template when i click next it goes to next station detail without creating a template for each of this stations? below are the logics.
this is my views.py and you can see from the commented line how i try to implement it but it did work.
def station_details(request, station_id):
my_blog =My_blog.objects.all()
slider = Slider.objects.all()
prayers = Prayers.objects.all()
stations_detail =Stationofcross.objects.get(title=station_id)
stations = Stationofcross.objects.all()
# next_station = Stationofcross.objects.filter(title=current_station.station_number + 1).first()
# detail_button = stations_detail.id + 1
context = {
'my_blog':my_blog,
'sliders':slider,
'prayers':prayers,
'stations_detail':stations_detail,
'stations':stations,
# 'detail_button':detail_button,
}
return render(request, 'blog/stations_detail.html', context)
this is the button in my template
<a class="btn btn-secondary" href="{% url 'station_details' detail_button.title %}">Next</a>
this is the model.py
class Stationofcross(models.Model):
title= models.CharField(max_length =100, null=True)
date =models.DateTimeField('Date Created', auto_now_add=True)
stationimages=models.ForeignKey('StationsImages', on_delete=models.CASCADE, null = True)
letuspray=models.ForeignKey(Stationsprayers, on_delete=models.CASCADE, null = True)
def __str__(self):
return self.title
please help me know the better way to achieve this