26👍
This has been possible since the queryset-refactor
branch landed pre-1.0. Ticket 4088 exposed the problem. This should work:
Asset.objects.filter(
desc__contains=filter,
project__name__contains="Foo").order_by("desc")
The Django Many-to-one documentation has this and other examples of following Foreign Keys using the Model API.
- [Django]-Duplicate column name
- [Django]-How do I filter query objects by date range in Django?
- [Django]-Django TypeError: get() got multiple values for keyword argument 'invoice_id'
0👍
student_user = User.objects.get(id=user_id)
available_subjects = Subject.objects.exclude(subject_grade__student__user=student_user) # My ans
enrolled_subjects = SubjectGrade.objects.filter(student__user=student_user)
context.update({'available_subjects': available_subjects, 'student_user': student_user,
'request':request, 'enrolled_subjects': enrolled_subjects})
In my application above, i assume that once a student is enrolled, a subject SubjectGrade instance will be created that contains the subject enrolled and the student himself/herself.
Subject and Student User model is a Foreign Key to the SubjectGrade Model.
In “available_subjects”, i excluded all the subjects that are already enrolled by the current student_user by checking all subjectgrade instance that has “student” attribute as the current student_user
PS. Apologies in Advance if you can’t still understand because of my explanation. This is the best explanation i Can Provide. Thank you so much
- [Django]-Django MultiValueDictKeyError error, how do I deal with it
- [Django]-Homepage login form Django
- [Django]-Django :How to integrate Django Rest framework in an existing application?