python - Django filter ManyToMany relationship from a single object -
i've got object in django, , 1 of it's properties manytomany relationship. ok, i've got object, , want know if there's data related, how can it?
here's code:
u = request.user ide = request.post['id'] defob = defobjc.objects.get(id=ide) if defob.filter(student_def=u).exists(): #do things
and here's object class:
class defobjc(models.model): name = models.charfield(max_length=100, blank=true, null=true) date = models.datetimefield(blank=true, null=true) student_def = models.manytomanyfield(user, related_name='defobjc_relation', blank=true, null=true)
how can that?
the result of get()
model instance, not queryset
, can't filter on it. instead:
if defob.student_def.filter(id=u.id).exists(): # things
Comments
Post a Comment