django m2m how can i get m2m table elements in a view
- by dana
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!