I have a Python script that will be called daily from a scheduled service
or daemon.
The script uses MySQLdb to read a csv file and import data into a MySQL
database that is used in my Django application.
Some of the models contain ManyToMany relationships. I am directly
inserting the relationships.
I thought that this was working great until I tried to query the models
from my Django view.
For example, I have a list of students, and each student has one or more
parents. Even though the students_student_parents table that stores the
student/parent relationship is updated by the script, when I run the query
to get a list of parents, the list is empty.
importedStudent = get_object_or_404(Student, pk=studentId)
logger.info(importedStudent)
the_parents = importedStudent.parents.all().values_list('id',
flat=True)
It appears that I have one of two choices:
1) Figure out what really happens under the covers when I add a parent to a
student in a Django form and call save() or save_m2m().
2) Instead of inserting data into my tables using MySQLdb cursor execute
methods, would it be better for me to create a service in my Django
application that my script can call?
Any suggestions?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/mjJFBffN-ZcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.