Django ticket form











up vote
0
down vote

favorite












So am trying to build an event ticket system but just got stuck at iterating over the ticket types in my model.
Basically a user can decide to choose whichever version of ticket they want e.g VIP, Regular, Advance e.t.c.
My problem lies in iterating over these types and letting someone pick the number of tickets they wish to buy. My code so far to handle this is less than stellar but i would really appreciate some help.



from django.shortcuts import render
from django.http import HttpResponse, HttpResponseNotFound, HttpResponseBadRequest
from .models import *
from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger


def allevents(request):
event_list = Event.objects.all()
carousel = Carousel.objects.filter(show_carousel=True)
page = request.GET.get('page', 1)

paginator = Paginator(event_list, 12)
try:
events = paginator.page(page)
except PageNotAnInteger:
events = paginator.page(1)
except EmptyPage:
events = paginator.page(paginator.num_pages)

return render(request, 'event/index.html', {'events':events, 'carousel':carousel})

def event_details(request, event_id=None):
try:
event = Event.objects.get(pk=event_id)
context = {
'event': event,
'ticket_form': TicketsForm(),
'cart' : request.session.get('cart', )
}
return render(request, 'event/event_detail.html', context)
except Event.DoesNotExist:
return HttpResponseNotFound('<h1>This event does not exist or has already taken place, sorry for the inconvinience</h1>')


my current template to handle that view is



<div class="grid-container" style="padding-top: 2%;">
<div class="work-feature-block grid-x grid-margin-x">
<div class="cell medium-6">
<img class="work-feature-block-image" src="{{ event.event_poster.url }}" />
</div>
<div class="cell medium-6">
<h2 class="work-feature-block-header">{{ event.name }}</h2>
<p>{{ event.description|safe|linebreaks }}</p>
<h2>Project Details</h2>
<form action="">

{% for eventamount in event.eventamount_set.all %}
<!-- PRODUCT -->
<div class="grid-x grid-margin-x">
<div class="cell medium-6">
<h4>{{ eventamount.amount_packages }}</h4>
<small>{{eventamount.amount}}</small>
</div>
<div class="cell medium-6">
<input type="number" class="idamount" id="{{eventamount.id}}" value='0'>
<input type="number" class="form-control" name="totaltickets" readonly>
</div>
</div>
<hr>
<!-- END PRODUCT -->
{% endfor %}
<input class="button" type="submit" value="submit">
</form>


</div>
</div>
</div>


Plus how do i get the total cost of the tickets within the template using javascript cause am really in a bind to have this working properly.



Thanks in advance for any help afforded.



Edit:
So am trying to iterate over the form that has the tickets types so that the user can pick the ticket they want and how many they would like to buy, then show the total cost of whatever they choose.
https://www.ticketsasa.com/events/eventdetail/view/2685/30_billion_concert



Something like that.










share|improve this question
























  • {{ eventamount | sum(attribute='amount') }} you can get the total like this and put in a div and use javascript to read the value in the div. What items are you trying to iterate over. Question too broad and confusing.
    – nara_l
    Nov 22 at 1:12















up vote
0
down vote

favorite












So am trying to build an event ticket system but just got stuck at iterating over the ticket types in my model.
Basically a user can decide to choose whichever version of ticket they want e.g VIP, Regular, Advance e.t.c.
My problem lies in iterating over these types and letting someone pick the number of tickets they wish to buy. My code so far to handle this is less than stellar but i would really appreciate some help.



from django.shortcuts import render
from django.http import HttpResponse, HttpResponseNotFound, HttpResponseBadRequest
from .models import *
from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger


def allevents(request):
event_list = Event.objects.all()
carousel = Carousel.objects.filter(show_carousel=True)
page = request.GET.get('page', 1)

paginator = Paginator(event_list, 12)
try:
events = paginator.page(page)
except PageNotAnInteger:
events = paginator.page(1)
except EmptyPage:
events = paginator.page(paginator.num_pages)

return render(request, 'event/index.html', {'events':events, 'carousel':carousel})

def event_details(request, event_id=None):
try:
event = Event.objects.get(pk=event_id)
context = {
'event': event,
'ticket_form': TicketsForm(),
'cart' : request.session.get('cart', )
}
return render(request, 'event/event_detail.html', context)
except Event.DoesNotExist:
return HttpResponseNotFound('<h1>This event does not exist or has already taken place, sorry for the inconvinience</h1>')


my current template to handle that view is



<div class="grid-container" style="padding-top: 2%;">
<div class="work-feature-block grid-x grid-margin-x">
<div class="cell medium-6">
<img class="work-feature-block-image" src="{{ event.event_poster.url }}" />
</div>
<div class="cell medium-6">
<h2 class="work-feature-block-header">{{ event.name }}</h2>
<p>{{ event.description|safe|linebreaks }}</p>
<h2>Project Details</h2>
<form action="">

{% for eventamount in event.eventamount_set.all %}
<!-- PRODUCT -->
<div class="grid-x grid-margin-x">
<div class="cell medium-6">
<h4>{{ eventamount.amount_packages }}</h4>
<small>{{eventamount.amount}}</small>
</div>
<div class="cell medium-6">
<input type="number" class="idamount" id="{{eventamount.id}}" value='0'>
<input type="number" class="form-control" name="totaltickets" readonly>
</div>
</div>
<hr>
<!-- END PRODUCT -->
{% endfor %}
<input class="button" type="submit" value="submit">
</form>


</div>
</div>
</div>


Plus how do i get the total cost of the tickets within the template using javascript cause am really in a bind to have this working properly.



Thanks in advance for any help afforded.



Edit:
So am trying to iterate over the form that has the tickets types so that the user can pick the ticket they want and how many they would like to buy, then show the total cost of whatever they choose.
https://www.ticketsasa.com/events/eventdetail/view/2685/30_billion_concert



Something like that.










share|improve this question
























  • {{ eventamount | sum(attribute='amount') }} you can get the total like this and put in a div and use javascript to read the value in the div. What items are you trying to iterate over. Question too broad and confusing.
    – nara_l
    Nov 22 at 1:12













up vote
0
down vote

favorite









up vote
0
down vote

favorite











So am trying to build an event ticket system but just got stuck at iterating over the ticket types in my model.
Basically a user can decide to choose whichever version of ticket they want e.g VIP, Regular, Advance e.t.c.
My problem lies in iterating over these types and letting someone pick the number of tickets they wish to buy. My code so far to handle this is less than stellar but i would really appreciate some help.



from django.shortcuts import render
from django.http import HttpResponse, HttpResponseNotFound, HttpResponseBadRequest
from .models import *
from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger


def allevents(request):
event_list = Event.objects.all()
carousel = Carousel.objects.filter(show_carousel=True)
page = request.GET.get('page', 1)

paginator = Paginator(event_list, 12)
try:
events = paginator.page(page)
except PageNotAnInteger:
events = paginator.page(1)
except EmptyPage:
events = paginator.page(paginator.num_pages)

return render(request, 'event/index.html', {'events':events, 'carousel':carousel})

def event_details(request, event_id=None):
try:
event = Event.objects.get(pk=event_id)
context = {
'event': event,
'ticket_form': TicketsForm(),
'cart' : request.session.get('cart', )
}
return render(request, 'event/event_detail.html', context)
except Event.DoesNotExist:
return HttpResponseNotFound('<h1>This event does not exist or has already taken place, sorry for the inconvinience</h1>')


my current template to handle that view is



<div class="grid-container" style="padding-top: 2%;">
<div class="work-feature-block grid-x grid-margin-x">
<div class="cell medium-6">
<img class="work-feature-block-image" src="{{ event.event_poster.url }}" />
</div>
<div class="cell medium-6">
<h2 class="work-feature-block-header">{{ event.name }}</h2>
<p>{{ event.description|safe|linebreaks }}</p>
<h2>Project Details</h2>
<form action="">

{% for eventamount in event.eventamount_set.all %}
<!-- PRODUCT -->
<div class="grid-x grid-margin-x">
<div class="cell medium-6">
<h4>{{ eventamount.amount_packages }}</h4>
<small>{{eventamount.amount}}</small>
</div>
<div class="cell medium-6">
<input type="number" class="idamount" id="{{eventamount.id}}" value='0'>
<input type="number" class="form-control" name="totaltickets" readonly>
</div>
</div>
<hr>
<!-- END PRODUCT -->
{% endfor %}
<input class="button" type="submit" value="submit">
</form>


</div>
</div>
</div>


Plus how do i get the total cost of the tickets within the template using javascript cause am really in a bind to have this working properly.



Thanks in advance for any help afforded.



Edit:
So am trying to iterate over the form that has the tickets types so that the user can pick the ticket they want and how many they would like to buy, then show the total cost of whatever they choose.
https://www.ticketsasa.com/events/eventdetail/view/2685/30_billion_concert



Something like that.










share|improve this question















So am trying to build an event ticket system but just got stuck at iterating over the ticket types in my model.
Basically a user can decide to choose whichever version of ticket they want e.g VIP, Regular, Advance e.t.c.
My problem lies in iterating over these types and letting someone pick the number of tickets they wish to buy. My code so far to handle this is less than stellar but i would really appreciate some help.



from django.shortcuts import render
from django.http import HttpResponse, HttpResponseNotFound, HttpResponseBadRequest
from .models import *
from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger


def allevents(request):
event_list = Event.objects.all()
carousel = Carousel.objects.filter(show_carousel=True)
page = request.GET.get('page', 1)

paginator = Paginator(event_list, 12)
try:
events = paginator.page(page)
except PageNotAnInteger:
events = paginator.page(1)
except EmptyPage:
events = paginator.page(paginator.num_pages)

return render(request, 'event/index.html', {'events':events, 'carousel':carousel})

def event_details(request, event_id=None):
try:
event = Event.objects.get(pk=event_id)
context = {
'event': event,
'ticket_form': TicketsForm(),
'cart' : request.session.get('cart', )
}
return render(request, 'event/event_detail.html', context)
except Event.DoesNotExist:
return HttpResponseNotFound('<h1>This event does not exist or has already taken place, sorry for the inconvinience</h1>')


my current template to handle that view is



<div class="grid-container" style="padding-top: 2%;">
<div class="work-feature-block grid-x grid-margin-x">
<div class="cell medium-6">
<img class="work-feature-block-image" src="{{ event.event_poster.url }}" />
</div>
<div class="cell medium-6">
<h2 class="work-feature-block-header">{{ event.name }}</h2>
<p>{{ event.description|safe|linebreaks }}</p>
<h2>Project Details</h2>
<form action="">

{% for eventamount in event.eventamount_set.all %}
<!-- PRODUCT -->
<div class="grid-x grid-margin-x">
<div class="cell medium-6">
<h4>{{ eventamount.amount_packages }}</h4>
<small>{{eventamount.amount}}</small>
</div>
<div class="cell medium-6">
<input type="number" class="idamount" id="{{eventamount.id}}" value='0'>
<input type="number" class="form-control" name="totaltickets" readonly>
</div>
</div>
<hr>
<!-- END PRODUCT -->
{% endfor %}
<input class="button" type="submit" value="submit">
</form>


</div>
</div>
</div>


Plus how do i get the total cost of the tickets within the template using javascript cause am really in a bind to have this working properly.



Thanks in advance for any help afforded.



Edit:
So am trying to iterate over the form that has the tickets types so that the user can pick the ticket they want and how many they would like to buy, then show the total cost of whatever they choose.
https://www.ticketsasa.com/events/eventdetail/view/2685/30_billion_concert



Something like that.







django forms formset






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 17:47

























asked Nov 22 at 0:27









Duncan Ireri

11




11












  • {{ eventamount | sum(attribute='amount') }} you can get the total like this and put in a div and use javascript to read the value in the div. What items are you trying to iterate over. Question too broad and confusing.
    – nara_l
    Nov 22 at 1:12


















  • {{ eventamount | sum(attribute='amount') }} you can get the total like this and put in a div and use javascript to read the value in the div. What items are you trying to iterate over. Question too broad and confusing.
    – nara_l
    Nov 22 at 1:12
















{{ eventamount | sum(attribute='amount') }} you can get the total like this and put in a div and use javascript to read the value in the div. What items are you trying to iterate over. Question too broad and confusing.
– nara_l
Nov 22 at 1:12




{{ eventamount | sum(attribute='amount') }} you can get the total like this and put in a div and use javascript to read the value in the div. What items are you trying to iterate over. Question too broad and confusing.
– nara_l
Nov 22 at 1:12

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422299%2fdjango-ticket-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422299%2fdjango-ticket-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks