On Dec 9, 9:43 pm, radioflyer <[EMAIL PROTECTED]> wrote:
> On Dec 9, 8:52 pm, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Dec 9, 2007 5:06 PM, radioflyer <[EMAIL PROTECTED]> wrote:
>
> > > parents = students.parents.all()
>
> > > And then check if logged in user.id matches against any of the parent
> > > ids.
>
> > It'd help if you shared your model definitions; any answers given will
> > be guesses as it is.
>
> > > Is there a query set method for this? If not, what would the Python
> > > look like? (Learning Python as I learn Django.)
>
> > There isn't a dedicated method to do what you want, but it's certainly
> > possible. Share your definitions and we'll be able to help better.
>
> Thanks Jeremy,
>
> Yes. Here's the Student model:
>
> class Student(models.Model):
> GRADE_CHOICES = (
> ('K', 'Kinder'),
> ('1', '!st Grade'),
> ('2', '2nd Grade'),
> ('3', '3rd Grade'),
> ('4', '4th Grade'),
> )
> parents = models.ManyToManyField(User, filter_interface=True)
> teacher = models.ForeignKey(Teacher)
> first_name = models.CharField(max_length=32, core=True)
> last_name = models.CharField(max_length=32, core=True)
> age = models.IntegerField(blank=True, null=True)
> class_year = models.IntegerField()
> grade = models.CharField(max_length=1, choices=GRADE_CHOICES)
> sibling = models.BooleanField()
> default_mon_scene = models.ForeignKey(Scenario,
> verbose_name="Monday", related_name='mon_scene')
> default_tue_scene = models.ForeignKey(Scenario,
> verbose_name="Tuesday", related_name='tue_scene')
> default_wed_scene = models.ForeignKey(Scenario,
> verbose_name="Wednesday", related_name='wed_scene')
> default_thu_scene = models.ForeignKey(Scenario,
> verbose_name="Thursday", related_name='thu_scene')
> default_fri_scene = models.ForeignKey(Scenario,
> verbose_name="Friday", related_name='fri_scene')
>
> As you can see, students have a m2m relationship with parents. When a
> user/parent logs in, they are redirected to a view which loads their
> students. If there are more than one, they are offered a choice of
> which one to edit. If only one, they go straight to that student's
> page.
>
> This is all fine, except that the authenticated user is free to travel
> to any student's page simply by altering the URL student.id parameter.
>
> In the student view, I want to check the student.id against the
> students associated with the currently logged in user. If they don't
> jibe, I will redirect back to the select_student view.
>
> I hope that makes my situation clearer.
>
> I was thinking I would iterate through the parent/user object looking
> for a matching student id, but not sure how.
I should have said, iterate through the parent/user query_set.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
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
-~----------~----~----~----~------~----~------~--~---