On Dec 9, 2007 8: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()
...
>
> class Student(models.Model):
> parents = models.ManyToManyField(User, filter_interface=True)
...
> As you can see, students have a m2m relationship with parents. When a
> user/parent logs in,
OK, so a parent is a user, and you want to check that the user is a
parent for the chosen student ID.
If I understand you correctly, this would be more like this:
def student_view(request, student_id):
student = Student.objects.get(student_id)
if student.parents.filter(pk=request.user.id).count() == 0:
raise Http404
....
Now, another approach would be to use a URL structure which doesn't
provide access to a given student ID, but rather limited access by the
parent.
Under that approach, /students/0/ (or even students/joe-smith/) would
mean different things based on which parent was using the site.
That approach would use
Student.objects.filter(parents__id=request.user.id) to get the list of
students for that parent, perhaps further filtering the queryset based
on the given ordinal or slug.
I generally prefer not to show raw IDs in the URL if I can help it,
since it makes DB merging/moving tougher and it affects search
results.
Cheers,
Jeremy
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---