{% for item ib images %}
<td><img src="{{ item.image }}" alt="" class="image" data-id="{{ item.id }}"></td>
{% endfor %}
let images = document.querySelectorAll('.image');
let modal = document.querySelector('.modal');
let modalImg = document.querySelector('.modal-content');
let modalClose = document.querySelector('.close');
var captionText = document.getElementById("caption");
for (let img of images) {
img.addEventListener('click', () => {
let id = img.getAttribute('data-id');
modalImg.src = images[id - 1].src;
modal.style.display = 'block';
captionText.innerHTML = img.getAttribute('alt');
});
}
var span = document.getElementsByClassName("close")[0];
span.onclick = function() { modal.style.display = "none";}
class LoginRequiredMixin(AccessMixin):
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return self.handle_no_permission()
if request.user.is_authenticated:
date_pass = Profile.objects.get(user=request.user.id).date_pass
if date.today() - date_pass > timedelta(days=90):
return HttpResponseRedirect(reverse_lazy('account_change_password'))
return super().dispatch(request, *args, **kwargs)
path('strani', StranaListView.as_view(), name='strani'),
path('new_strana', StranaCreate.as_view(), name='new_strana'),
path('goroda', GorodListView.as_view(), name='goroda'),
path('new_gorod', GorodCreate.as_view(), name='new_gorod')
class GorodCreate(generic.CreateView):
model = Gorod
form_class = GorodForm
template_name = 'main/create_gorod.html'
context_object_name = 'gorod'
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
post = form.save(commit=False)
post.strana_id = #???
post.save()
return HttpResponseRedirect('strani')