django m2m how can i get m2m table elements in a view
Posted
by dana
on Stack Overflow
See other posts from Stack Overflow
or by dana
Published on 2010-06-17T13:40:07Z
Indexed on
2010/06/17
13:43 UTC
Read the original article
Hit count: 294
i have a model using m2m feature:
class Classroom(models.Model):
user = models.ForeignKey(User, related_name = 'classroom_creator')
classname = models.CharField(max_length=140, unique = True)
date = models.DateTimeField(auto_now=True)
open_class = models.BooleanField(default=True)
members = models.ManyToManyField(User,related_name="list of invited members", through = 'Membership')
and i want to take all members of one class in a view and display them using the template system. In the view, i'm trying to take all the members from a classroom like that:
def inside_classroom(request,classname):
try:
theclass = Classroom.objects.get(classname = classname)
members = Members.objects.all()
etc
but it doesn't work,(though the db_table is named Classroom_Members) i guess i have to use another query for getting all the members from the classroom classname. also, i want to verify if the request.user is a member using (if request.user in members)
how can i het those members? Thanks in advance!
© Stack Overflow or respective owner