Looking for COMPSCI2021 Web Application Development 2 - 2024-25 test answers and solutions? Browse our comprehensive collection of verified answers for COMPSCI2021 Web Application Development 2 - 2024-25 at moodle.gla.ac.uk.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
For the following 2 questions, assume a template has been written to display, for a given constituency, a table of all election candidates and their vote counts, including the following code:
<table border> {% for candidate in candidates %} <tr> <!-- *** Insert code here--> </tr> {% endfor %}</table>
In the view which loads this template, what of the following steps would we need to take?
In the election app's views.py file there is a function named all_candidates that retrieves and lists all candidates standing in the most recent election.
Which of the following lines could also be added to the urlpatterns list in urls.py?
For the following 2 questions, consider that in the election app's views.py file there is a function named show_constituency which displays information on a constituency specified by the URL. Assume that each constituency's name contains just one word.
In the election app's urls.py file, there is a urlpatterns list that is currently empty. Which of the following lines should be added to this list?
The process of adding a candidate is accomplished via a form. For this purpose, the class CandidateForm, which subclasses ModelForm, has been created in forms.py.
Which one of the following lines of code should NOT appear within class CandidateForm?
The following line of Django code is run, where a Constituency object does not already exist in your database with name equal to the value of n and eligible_voter_population equal to p.
c = Constituency.objects.get_or_create(name=n, eligible_voter_population =p)[1]
What value is assigned to c?
An HTML template add_candidate.html has been created to create the HTML form to capture user input.
Which of the following steps should be taken within the template file?
A web page to display election results wants to display the 5 candidates for a given constituency c and election e with the least votes, ordered by number of votes received (starting with the lowest number at the top).
Which of the following lines of code could appear in a Django view to correctly retrieve this information?
For section C of this exam, consider the following Django models that are part of a web app to collate and display UK election results for the site www.ukelectionresults.com:
class Election(models.Model): date = models.DateField()class Constituency(models.Model): name = models.CharField(max_length=128) eligible_voter_population = models.IntegerField(default=0)
class ElectionCandidate(models.Model): name = models.CharField(max_length=128) votes = models.IntegerField(default=0) constituency = models.ForeignKey(Constituency, on_delete=models.CASCADE) election = models.ForeignKey(Election, on_delete=models.CASCADE)
What recommendation could you make that would be good development practice for the Constituency model?