Belated thanks, Karen-- I was indeed logged in (as "root") in a nearby  
admin screen.

I'm having a devil of a time conceptualizing this model, & I know what  
I have below isn't correct.  I'm trying to set up a simple form; each  
user would get to select how convenient several different   
meetingtimes would be for them:

Mon 1:30-3:30, Tu 10-12, Th 1:30-3:30, F 1:30-3:30

...would be the times, & the convenience choices would be as below ("I  
can make this time regularly", etc).

Seems like it should be really simple, but I can't get my head around  
it.  I put in the unique_together bit thinking that would prohibit a  
user from selecting two different convenience levels for the same  
time, but that's probably not the way to go about that either.

I got our product database online remarkably quickly w/Django, but  
this simple little poll is really proving to be my Waterloo, & I  
really feel like I need to get my head around it before I can go any  
further w/the framework.  Thus, any suggestion/help much much  
appreciated!


On Jan 22, 2008, at 7:54 PM, Karen Tracey wrote:

> On Jan 22, 2008 10:16 PM, Jason Witherspoon  
> <[EMAIL PROTECTED]> wrote:
> Hi folks--
>
> I've got the following code in a view:
>
> from django.shortcuts import get_object_or_404, render_to_response
> from django.http import HttpResponseRedirect
> from django.core.urlresolvers import reverse
> from mysite.officemeetingpoll.models import Meetingtime
> from django.contrib.auth.decorators import login_required
> from django.contrib.auth import authenticate, login
> from django.newforms import form_for_instance
>
> @login_required
> def vote(request):
>        m = Meetingtime.objects.get(user=request.user)
>        UserForm = form_for_instance(m)
>        f = UserForm(auto_id=False)
>        return render_to_response('officemeetingpoll/form.html',  
> {'form':f})
>
> I'm hoping this will check if the user is logged in, go to the default
> login page & redirect back if not, & then render an edit form for the
> office meeting poll.
>
> Here's the model:
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class Meetingtime(models.Model):
>        time = models.CharField(max_length=40)
>        user = models.ManyToManyField(User, blank=True, null=True)
>        CONVENIENCE_CHOICES = (
>                ('A', 'I can make this time regularly'),
>                ('S', 'I could occasionally make this time'),
>                ('N', 'I could rarely if ever make this time'),
>        )
>        convenience = models.CharField(max_length=1,
> choices=CONVENIENCE_CHOICES)
>        unique_together = (("user", "time"),)
>        def __unicode__(self):
>                return self.time
>        class Admin:
>                list_display = ('time', 'convenience')
>                fields = (
>                        (None, {'fields': ('time', 'convenience',  
> 'user')}),
>                )
>
>
>
> However, it doesn't send me to the login page, it generates the
> following error:
>
>
> DoesNotExist at /officepoll/officepolls/
> Meetingtime matching query does not exist.
> Request Method:         GET
> Request URL:    http://www.rainbow.coop/officepoll/officepolls/
> Exception Type:         DoesNotExist
> Exception Value:        Meetingtime matching query does not exist.
> Exception Location:     /usr/local/lib/python2.5/site-packages/ 
> django/db/
> models/query.py in get, line 263
> Python Executable:      /usr/local/bin/python
> Python Version:         2.5.1
> Python Path:    ['/home/jason/killdjangokill', '/usr/local/lib/ 
> python2.5/
> [snipped]
>
> ...which is no surprise, since the view is relying upon the logged-in
> user info, & I'm not getting redirected to the login page, so there's
> no user info to match.
>
> Now, this is my first run at this, & frankly (& obviously, no doubt)
> I'm more than a bit baffled by the whole sessions framework business.
> Am I anywhere in the ballpark?  Any advice much appreciated!
>
> Are you sure you are not logged in?  If you assign a local variable  
> to the value of request.user before trying the get then when you get  
> the debug page you can see the user value among the local  
> variables.  If it's a django.contrib.auth.models.AnonymousUser, then  
> somehow you got past the @login_required without logging in.  I  
> think it's more likely you are logged in and no Meetingtime matching  
> your user exists.  (Also, are you sure you want a get there?  Using  
> get implies there will be exactly one Meetingtime per user,  
> otherwise the get will raise an exception.)
>
> Karen
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to