Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
SyntaxError trying to access foreign key in the view function

The function is not accepting the foreign key. It is getting a syntax error. This is the code of the function. views.py

def projectoraccept(request, eventprojector_id):
    eventprojector = get_object_or_404(Eventprojector, pk=eventprojector_id)
    if request.method == 'POST':
        eventprojector.is_accept = eventprojector.is_accept+1
        eventprojector.save(update_fields=['is_accept'])

    if eventprojector.projector.sec.sec_name == 'CS_dept'
        eventprojector.projector.cs_no = eventprojector.projector.cs_no-1
        eventprojector.projector.save(update_fields=['sec'])
    elif eventprojector.projector.sec.sec_name is EC dept
        eventprojector.projector.ec_no = eventprojector.projector.ec_no-1
        eventprojector.projector.save(update_fields=['sec'])
    elif eventprojector.projector.sec.sec_name is EEE dept
        eventprojector.projector.eee_no = eventprojector.projector.eee_no-1
        eventprojector.projector.save(update_fields=['sec'])
    elif eventprojector.projector.sec.sec_name is IEEE
        eventprojector.projector.ieee_no = eventprojector.projector.ieee_no-1
        eventprojector.projector.save(update_fields=['sec'])
    elif eventprojector.projector.sec.sec_name is TCP dept
        eventprojector.projector.tcp_no = eventprojector.projector.tcp_no-1
        eventprojector.projector.save(update_fields=['sec'])
return render(request, 'event/projectordetails.html' , {'eventprojector' : eventprojector })

The error is

if eventprojector.projector.sec_name == 'CS_dept' ^ SyntaxError: invalid syntax
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You don'the have the colon : char after the if conditions; e.g. they should be:

if eventprojector.projector.sec.sec_name == 'CS_dept':

, and so on.

The error says "SyntaxError" for a reason :)

over 4 years ago · Santiago Trujillo Report

0

You must add a colon after each if and elif for example :

if eventprojector.projector.sec.sec_name == 'CS_dept' :
    # your if condition code
elif eventprojector.projector.sec.sec_name is EC dept :
   # your elif condition code
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!