Posted under » PHP » Python » Django on 29 Jun 2021
In PHP you end a line with ; but in Python, you have to pay attention to your indent. It may not cause an error for Python but the logic could be problematic.
Concatenate of strings is different in python. In python, you do this where goyay is an integer.
goyayurl = '/feels/'+ str(goyay) +'/'
In PHP we do this.
$goyayurl = '/feels/'.$goyay.'/';
However for python, you use . to concatenate commands eg.
c_title = a_title.replace('\n', ' ').replace('\\','\\\\')
MySQL update in PHP may look like this.
mysqli_query($dbhandle, "UPDATE consent SET answered = $question_id WHERE student_id=$study");
Where in Django it look less SQL but more python
Profile.objects.filter(id=current_user_id).update(status = '02')
To insert it look like this
for consent in Consent.objects.filter(student_id=study): consent.answered = question_id consent.save()
In Python, greater than
Entry.objects.filter(id__gt=4)
In PHP the SQL is
SELECT ... WHERE id > 4;
Other examples of making queries
String filter Case-sensitive starts-with.
Entry.objects.filter(headline__startswith='Lennon')
In Php more sql
SELECT ... WHERE headline LIKE 'Lennon%';
In PHP we use 'elseif' but in Python we use 'elif'
See also Django filter. More on Django query.