Re: help to finish my 1st Django app.

2011-03-14 Thread Rogelio Gonzalez
Hi Igor.

Thanks for your reply. My poll_list.html code is:

{% if latest_poll_list %}

{% for poll in latest_poll_list %}
{{ poll.question }}
{% endfor %}

{% else %}
No polls are available.
{% endif %}
What i'm doing wrong?..

2011/3/14 royy 

> Hi.
>
> I've finished the tutorial for the polls app.
>
> I tought everythin was OK till I load the server and type the addres:
> http://127.0.0.1:8000/polls/
>
> web browser shows me the message "No polls are available" isn't a web
> browser error message, because it is plain text.
>
> I've created 3 polls with 3 choices each one.
>
> admin page works fine, just the polls address is the one that don't
> loads well. This is my final views.py code:
>
> from django.shortcuts import get_object_or_404, render_to_response
> from django.http import HttpResponseRedirect, HttpResponse
> from django.core.urlresolvers import reverse
> from django.template import RequestContext
> from polls.models import Choice, Poll
>
> def vote(request, poll_id):
>p = get_object_or_404(Poll, pk=poll_id)
>try:
>selected_choice = p.choice_set.get(pk=request.POST['choice'])
>except (KeyError, Choice.DoesNotExist):
>
>return render_to_response('polls/poll_detail.html', {
>'poll': p,
>'error_message': "You didn't select a choice.",
>}, context_instance=RequestContext(request))
>else:
>selected_choice.votes += 1
>selected_choice.save()
>return HttpResponseRedirect(reverse('poll_results',
> args=(p.id,)))
>
>
> -
>
> and this is my final polls/urls.py code:
>
> from django.conf.urls.defaults import *
> from polls.models import Poll
>
> info_dict = {
>'queryset': Poll.objects.all(),
> }
>
> urlpatterns = patterns('',
>(r'^$', 'django.views.generic.list_detail.object_list',
> info_dict),
>(r'^(?P\d+)/$',
> 'django.views.generic.list_detail.object_detail', info_dict),
>url(r'^(?P\d+)/results/$',
> 'django.views.generic.list_detail.object_detail', dict(info_dict,
> template_name='polls/results.html'), 'poll_results'),
>(r'^(?P\d+)/vote/$', 'polls.views.vote'),
> )
>
>
> Please help me to find what's wrong.
>
> Thanks
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: URL design for security?

2007-07-14 Thread Rogelio

Thanks for the replies.  No, I haven't incorporated authentication
yet.  I guess I was
thinking that even if the user was logged in, the URL still would be
showing potentially
sensitive info.  I was thinking maybe I needed to create some random
sequence of
letters/numbers, store that in a model field and use it as the pk
which would then
up in the URL params.  Probably overkill with my limited experience.
I'll take a look
at the authentication module and try some tests.  Thanks again.

Rog


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



URL design for security?

2007-07-14 Thread Rogelio

Hi,

I'm starting to write a grade book type application.  There will be
many teachers that will be logging in to access their student
records.  The student record will contain student grades and sensitive
info such as student ID number.  In the model each teacher will have a
primary key (pk) and each student will have a primary key.  So if
teacher (with pk=21) logs in and wants to update the grade for student
(pk=197), the URL I'm calling to retrieve that view is "/grades/
21/197" (ie, on the teacher page there would be a list of student
names each being an  as shown).   I feel like
by using this scheme
I'm giving away too much info in the URL.  Some other teacher (or
person) who is NOT teacher (pk=21)
could just enter that URL and look at some other teacher's grades just
by "guessing" what pk to
plug into the URL.  What if the student pk was actually his SSN, then
I wouldn't want that as part of the URL for sure.

So my newbie question is:  Is there a way a better way to design/
obfuscate the URL scheme when dealing with sensitive information?   I
know once I get some sort of authentication in place that will help,
but the idea of showing sensitive info in a URL still has me
concerned.

Thanks in advance.
Rog


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Eclipse and PyDev setup

2007-07-11 Thread Rogelio

Hi,

I'm a newbie as well, but have a project I developed using
Eclipse and Pydev.  Bascially, I just unchecked the "Create
src folder" option for the Pydev project and all seems OK so far.
Can't help with Apache yet as I just use the Django builtin server
from within Eclipse and start/stop the server there.

Rog

On Jul 11, 10:40 am, "Sells, Fred" <[EMAIL PROTECTED]> wrote:
> I'm using Eclipse 3.2 and latest PyDev.
>
> I'm a django newbie, just finished the tutorial.  I would like to do my
> development under Eclipse.  PyDev want to have a "src" folder under the
> project, which does not really fit the django default directory structure.
>
> mysite (an Elcipse project)
> polls
> templates
> settings.py
> ...
>
> I'm not sure of the cleanest way to get the functionality of the "src"
> folder:
> 1. Is there a way to define the project folder as being the "src" folder?
> 2. Should I create a "dummy" project and then have all the django stuff
> under it's src folder
> 3. ???
>
> For development purposes, I would like to have Apache point to the django
> project root (mydjangodemo above).  So changes are immediately available,
> eliminating a "deploy" cycle.
>
> Any suggestions?
>
> ---
> The information contained in this message may be privileged and / or
> confidential and protected from disclosure. If the reader of this message is
> not the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited. If you
> have received this communication in error, please notify the sender
> immediately by replying to this message and deleting the material from any
> computer.
> ---


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

On May 23, 3:10 pm, Rogelio <[EMAIL PROTECTED]> wrote:
> Thank you so much!  I was able to get your first method to work.  The
> second method
> seemed to be complaining that I was using a for-loop on an empty
> "photo_set".
> I'll play around it some more.
>
> Rogelio


Sorry for the multiple "thanks" -- on my end I was getting a message
that there
was an error posting the reply and I should try again later -- which I
did several
times.  I guess there was no error after all.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Thank you so much!  I was able to get your first method to work.  The
second method
seemed to be complaining that I was using a for-loop on an empty
"photo_set".
I'll play around it some more.

Rogelio


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Thank you so much!  I was able to get your first method to work.  The
second method
seemed to be complaining that I was using a for-loop on an empty
"photo_set".
I'll play around it some more.

Rogelio


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Thank you so much!  I was able to get your first method to work.  The
second method
seemed to be complaining that I was using a for-loop on an empty
"photo_set".
I'll play around it some more.

Rogelio


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



NEWBIE: joining two tables problem

2007-05-23 Thread Rogelio

Hello.  Newbie to django and first-time poster to this group.

I've got two models (basic structure shown below):

class Employee(models.Model):
 name = models.CharField(maxlength=50)
 office = models.CharField(maxlength=20)
 phone= models.CharField(maxlength=15)

class Photo(models.Model):
 filename = models.CharField(maxlength=50)
 master_photo = models.BooleanField()
 employee = models.ForeignKey(Employee)

In one of my views I'd like to have a table consisting of rows like:



but if I say:

object_list = Employee.objects.order_by('name')

and pass "object_list" to my listing.html template, it doesn't have
the Photo information.

I've resorted to using straight SQL to build the query:

def employee_view_list(self):
 from django.db import connection
 cursor = connection.cursor()
 cursor.execute("select e.id, e.name, e.office, p.filename
from company_employee e, company_photo p where p.employee_id=e.id and
p.master_photo='T'")
 rows = cursor.fetchall()
 return rows

This sort of works and returns  a list-of-lists, but I can't use the
convention {{employee.name}} in the
template since the returned rows do not include the header
information.

Questions:

1) Is there a better way to join these tables using the django model
methods?
2) Is there an better way to use straight SQL and still be able to use
things like {{employee.name}}
in the templates?
3) I tried making the Photo table have a "many2manyfield" on Employee
rather an
a ForeignKey.  I rebuilt the database using syncdb, but when I tried
to enter photo info
via the admin interface, I got an "operational error".  I could edit
the other database tables
fine.  Ideas?  I tried using the latest stable django and the SVN from
today with the same
result.

Thanks in advance.
Rogelio


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---