How to Detect Current Page as Homepage?

2012-03-24 Thread easypie
I'm trying to check {% if homepage %} then show  {% endif %}

I'm not sure how to go about a test to check the current page if it's my 
homepage. Do I need to mess around with context processors? What's the 
usual way of doing it? And how would the {% if ... %} look like?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0e6Qif6N9QQJ.
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: __unicode__ and return.self

2012-03-24 Thread spike
Thanks for the reply.

Why am I only returning one or two fields from each model? If I define 5 
fields, shouldn't I return all 5?


On Saturday, March 24, 2012 9:19:51 PM UTC-7, jondbaker wrote:
>
> The __unicode__ method allows models to return a more usable 
> representation of a record instead of a unicode object. This is useful in a 
> variety of places, from the Django admin to using the manage.py shell on 
> the command line.
>
> The return statement effectively ends the execution of a particular 
> function or method by returning something (an object, string, whatever you 
> may need to return for the task at hand).
>
> On Sat, Mar 24, 2012 at 10:10 PM, spike  wrote:
>
>> Running the tut here:  
>> https://docs.djangoproject.​com/en/1.1/intro/tutorial01/
>>   
>> but I'm having trouble understanding what the point of __unicode__ is. 
>> Also, what is the point of the return statements? I've read the docs over 
>> and over but don't get it. 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/​msg/django-users/-/​jKgyKR2iRdgJ
>> .
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscribe@​googlegroups.com
>> .
>> For more options, visit this group at 
>> http://groups.google.com/​group/django-users?hl=en
>> .
>>
>
>
>
> -- 
> Jonathan D. Baker
> Web Developer
> http://jonathandbaker.com
> 303.257.4144
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/IFpUg5EEj7oJ.
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: all(), get(), create(), count(). More info?

2012-03-24 Thread Jonathan Baker
.all(), .filter(), .get() are methods invoked through Django model managers
('objects' in this case).  The methods are made available when you create a
model class that inherits from models.Model. To use any of them from a
shell, you'll need to invoke the python interpreter using the following
manage.py command to load the Django environment and then import the
necessary models:
$ python manage.py shell
>>>from mysite.polls.models import Poll
>>>your code here...

On Sat, Mar 24, 2012 at 11:31 PM, MF-DOS  wrote:

> Running this tut: https://docs.djangoproject.com/en/1.1/intro/tutorial01/
>
> Here is a list of shell commands I'm asked to issue, but I don't
> understand where the commands are coming from? Are these Django or
> Python commands? I've attempted to query help and read the docs but
> can't find them anywhere.
>
> Poll.objects.all()
> Poll.objects.filter()
> Poll.objects.get()
> p.choice_set.all()
> p.choice_set.create()
> p.choice_set.count()
>
> --
> 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.
>
>


-- 
Jonathan D. Baker
Web Developer
http://jonathandbaker.com
303.257.4144

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



all(), get(), create(), count(). More info?

2012-03-24 Thread MF-DOS
Running this tut: https://docs.djangoproject.com/en/1.1/intro/tutorial01/

Here is a list of shell commands I'm asked to issue, but I don't
understand where the commands are coming from? Are these Django or
Python commands? I've attempted to query help and read the docs but
can't find them anywhere.

Poll.objects.all()
Poll.objects.filter()
Poll.objects.get()
p.choice_set.all()
p.choice_set.create()
p.choice_set.count()

-- 
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: __unicode__ and return.self

2012-03-24 Thread Jonathan Baker
Glad to help. How the record is represented is up to you. For instance, if
I have a Person model with the fields first_name, middle_name, last_name,
email_address and phone number, I would think it prudent to define
__unicode__ as:

def __unicode__(self):
return '%s %s' % (self.first_name, self.last_name)

... since first + last name is a common representation for a person. It
would be just as valid (and perhaps even more usable in some situations) to
return a middle name as well.

On Sat, Mar 24, 2012 at 10:34 PM, MF-DOS  wrote:

> Thanks for the reply.
>
> If my model has 5 fields, why am I only returning one or two?
> Shouldn't I return all 5?
>
> On Mar 24, 9:19 pm, Jonathan Baker 
> wrote:
> > The __unicode__ method allows models to return a more usable
> representation
> > of a record instead of a unicode object. This is useful in a variety of
> > places, from the Django admin to using the manage.py shell on the command
> > line.
> >
> > The return statement effectively ends the execution of a particular
> > function or method by returning something (an object, string, whatever
> you
> > may need to return for the task at hand).
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Sat, Mar 24, 2012 at 10:10 PM, spike  wrote:
> > > Running the tut here:
> > >https://docs.djangoproject.com/en/1.1/intro/tutorial01/ but I'm having
> > > trouble understanding what the point of __unicode__ is. Also, what is
> the
> > > point of the return statements? I've read the docs over and over but
> don't
> > > get it.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Django users" group.
> > > To view this discussion on the web visit
> > >https://groups.google.com/d/msg/django-users/-/jKgyKR2iRdgJ.
> > > 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.
> >
> > --
> > Jonathan D. Baker
> > Web Developerhttp://jonathandbaker.com
> > 303.257.4144
>
> --
> 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.
>
>


-- 
Jonathan D. Baker
Web Developer
http://jonathandbaker.com
303.257.4144

-- 
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: __unicode__ and return.self

2012-03-24 Thread MF-DOS
Thanks for the reply.

If my model has 5 fields, why am I only returning one or two?
Shouldn't I return all 5?

On Mar 24, 9:19 pm, Jonathan Baker 
wrote:
> The __unicode__ method allows models to return a more usable representation
> of a record instead of a unicode object. This is useful in a variety of
> places, from the Django admin to using the manage.py shell on the command
> line.
>
> The return statement effectively ends the execution of a particular
> function or method by returning something (an object, string, whatever you
> may need to return for the task at hand).
>
>
>
>
>
>
>
>
>
> On Sat, Mar 24, 2012 at 10:10 PM, spike  wrote:
> > Running the tut here:
> >https://docs.djangoproject.com/en/1.1/intro/tutorial01/ but I'm having
> > trouble understanding what the point of __unicode__ is. Also, what is the
> > point of the return statements? I've read the docs over and over but don't
> > get it.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To view this discussion on the web visit
> >https://groups.google.com/d/msg/django-users/-/jKgyKR2iRdgJ.
> > 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.
>
> --
> Jonathan D. Baker
> Web Developerhttp://jonathandbaker.com
> 303.257.4144

-- 
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: __unicode__ and return.self

2012-03-24 Thread Jonathan Baker
The __unicode__ method allows models to return a more usable representation
of a record instead of a unicode object. This is useful in a variety of
places, from the Django admin to using the manage.py shell on the command
line.

The return statement effectively ends the execution of a particular
function or method by returning something (an object, string, whatever you
may need to return for the task at hand).

On Sat, Mar 24, 2012 at 10:10 PM, spike  wrote:

> Running the tut here:
> https://docs.djangoproject.com/en/1.1/intro/tutorial01/  but I'm having
> trouble understanding what the point of __unicode__ is. Also, what is the
> point of the return statements? I've read the docs over and over but don't
> get it.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/jKgyKR2iRdgJ.
> 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.
>



-- 
Jonathan D. Baker
Web Developer
http://jonathandbaker.com
303.257.4144

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



__unicode__ and return.self

2012-03-24 Thread spike
Running the tut here:  
https://docs.djangoproject.com/en/1.1/intro/tutorial01/  but I'm having 
trouble understanding what the point of __unicode__ is. Also, what is the 
point of the return statements? I've read the docs over and over but don't 
get it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/jKgyKR2iRdgJ.
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: Template Error: Invalid block tag: 'endblock', expected 'empty' or 'endfor'

2012-03-24 Thread Jesramz
Is there an {% endblock footer %} ?

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



Template Error: Invalid block tag: 'endblock', expected 'empty' or 'endfor'

2012-03-24 Thread Homer
I tried to create an index webpage but Django told me I had a template 
error: 
Invalid block tag: 'endblock', expected 'empty' or 'endfor'
Here is the code of index.html:

{% extends "base.html" %}

{% block title %}Home{% endblock %}
{% block content %}

Welcome to So Easy! 学中文

Showcase


{% for item in item_list|slice:":3" %}

{{ item.name }}
{% if item.photo_set.count %}

{% else %}
No Photos (yet)
{% endif %}


<% endfor %>


View the full list;

{% endblock %}#Error Here
{% block footer %}

I hope someone can help me. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Dn_zBeC7tnYJ.
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.



Keep getting 404 error

2012-03-24 Thread Mika
I'm a total newbie to django and just started the book. I created a
project and I'm now trying to create my first page, but I keep getting
an error page that says:

Page not found (404)
Request Method: GET
Request URL:http://127.0.0.1:8000/
Using the URLconf defined in redlab.urls, Django tried these URL
patterns, in this order:
^hello/$
The current URL, , didn't match any of these.


Here's what's in my urls.py file:

from django.conf.urls.defaults import*
from redlab.views import hello

urlpatterns = patterns('', ('^hello/$', hello),)

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
# Examples:
# url(r'^$', 'redlab.views.home', name='home'),
# url(r'^redlab/', include('redlab.foo.urls')),

# Uncomment the admin/doc line below to enable admin
documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),


please advise. thnx.

-- 
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: filtered admin change-list

2012-03-24 Thread omerd
thank you, it worked. I  wrote queryset, has_change_permission and
save_model in my ModelAdmin.
As i see it, django-guardian intended for low level permissions in the
web application itself, not the admin-interface.

By the way, is it safe and secure to allow any user (which is not
superuser and is not trusted) to log in the admin interface (by
marking every new user as 'is_staff'=True) when restricting his
permissions to change only the objects he owns?

On Mar 23, 11:33 am, Marc Aymerich  wrote:
> On Sun, Mar 18, 2012 at 12:07 AM, omerd  wrote:
> > Hi,
>
> > I want to be able to show parts of the change list, by the user that
> > view it.
> > The case is that every super-user can create instances of a certain
> > model. I wan't that in the change-list page of that model in the admin
> > site, every user will see only the instances that he'd created. Of
> > course, this user doesn't have permissions to view or edit instances
> > of other users.
>
> > What is the best approach to accomplish this?
>
> take a look at this project:https://github.com/lukaszb/django-guardian
>
> or search in google by: django admin row level permission
> --
> Marc

-- 
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: Admin - how to get all registeres models in templatetag?

2012-03-24 Thread dummyman dummyman
Yes it is possible

override the django admin template

http://www.djangobook.com/en/1.0/chapter17/

this link would b helpful

On Thu, Mar 22, 2012 at 3:49 PM, rohit jangid wrote:

> I'm using the default admin for my purpose there was a time when I was
> thinking the same but I didn't wanted to reinvent the wheel so
> what different features are u planning for it which are not available
> in default admin?
>
>
> On Thu, Mar 22, 2012 at 3:33 PM, galgal  wrote:
> > I'm writing a custom admin stuff and need to get all registered models in
> > Admin. Is this possible?
> > I need it to make some custom views on admin index page.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/django-users/-/ZGg0w69RYhMJ.
> > 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.
>
>
>
> --
> Rohit Jangid
> Under Graduate Student,
> Deptt. of Computer Engineering
> NSIT, Delhi University, India
>
> --
> 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: Customizie admin views

2012-03-24 Thread John S. Dey
Thanks so very much for the advise.  I'll give it a try.
On Mar 24, 2012, at 2:23 PM, dummyman dummyman wrote:

> in admin.py
> 
> # import your model
> from django.contrib import admin
> 
> 
> class MyAdmin(admin.ModelAdmin):
> def response_change(self,request,obj):
>   
>   result = super(MyAdmin, self).response_change(request, obj) 
> document=Yourmodel.objects.get(idcontent=obj.idcontent)
>  #rest of the code
> 
> On Sat, Mar 24, 2012 at 11:40 PM, John S. Dey  wrote:
> Thanks for the tip.  I'm new to django/python and need a little bit of 
> coaching.  I found the response_change method in options.py as part of the 
> ModelAdmin class.  What is the best way to override?  Could I create a class 
> that inherits ModelAdmin and place the modified response_change in it.  Would 
> this code be added to my admin.py residing in my app directory?  Or could I 
> bring the whole class down in insert in my admin.py?  Any guidance would be 
> much appreciated.  Thanks 
> 
> John
> 
> On Mar 24, 2012, at 1:23 PM, dummyman dummyman wrote:
> 
>> hi
>> 
>> u can override response_change method
>> def response_change(self,request,obj):
>>  
>>  
>> 
>> On Fri, Mar 23, 2012 at 7:33 PM, jsdey  wrote:
>>  I have a project photos that has a model Album.  Admin (/admin/photos/
>> album/  page has a button "Add Album".  I want to write a custom page
>> for that action but can't find the view that does the processing.  Any
>> guidance would be appreciated.  Thanks.
>> 
>> John
>> 
>> --
>> 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.
> 
> 
> -- 
> 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.

-- 
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: Customizie admin views

2012-03-24 Thread dummyman dummyman
in admin.py

# import your model
from django.contrib import admin


class MyAdmin(admin.ModelAdmin):
def response_change(self,request,obj):
 result = super(MyAdmin, self).response_change(request, obj)
document=Yourmodel.objects.get(idcontent=obj.idcontent)
 #rest of the code

On Sat, Mar 24, 2012 at 11:40 PM, John S. Dey  wrote:

> Thanks for the tip.  I'm new to django/python and need a little bit of
> coaching.  I found the response_change method in options.py as part of the
> ModelAdmin class.  What is the best way to override?  Could I create a
> class that inherits ModelAdmin and place the modified response_change in
> it.  Would this code be added to my admin.py residing in my app directory?
>  Or could I bring the whole class down in insert in my admin.py?  Any
> guidance would be much appreciated.  Thanks
>
> John
>
> On Mar 24, 2012, at 1:23 PM, dummyman dummyman wrote:
>
> hi
>
> u can override response_change method
> def response_change(self,request,obj):
>
> On Fri, Mar 23, 2012 at 7:33 PM, jsdey  wrote:
>
>>  I have a project photos that has a model Album.  Admin (/admin/photos/
>> album/  page has a button "Add Album".  I want to write a custom page
>> for that action but can't find the view that does the processing.  Any
>> guidance would be appreciated.  Thanks.
>>
>> John
>>
>> --
>> 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.
>
>
>  --
> 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: Customizie admin views

2012-03-24 Thread John S. Dey
Thanks for the tip.  I'm new to django/python and need a little bit of 
coaching.  I found the response_change method in options.py as part of the 
ModelAdmin class.  What is the best way to override?  Could I create a class 
that inherits ModelAdmin and place the modified response_change in it.  Would 
this code be added to my admin.py residing in my app directory?  Or could I 
bring the whole class down in insert in my admin.py?  Any guidance would be 
much appreciated.  Thanks 

John
On Mar 24, 2012, at 1:23 PM, dummyman dummyman wrote:

> hi
> 
> u can override response_change method
> def response_change(self,request,obj):
>   
>   
> 
> On Fri, Mar 23, 2012 at 7:33 PM, jsdey  wrote:
>  I have a project photos that has a model Album.  Admin (/admin/photos/
> album/  page has a button "Add Album".  I want to write a custom page
> for that action but can't find the view that does the processing.  Any
> guidance would be appreciated.  Thanks.
> 
> John
> 
> --
> 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.

-- 
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: Customizie admin views

2012-03-24 Thread dummyman dummyman
hi

u can override response_change method
def response_change(self,request,obj):

On Fri, Mar 23, 2012 at 7:33 PM, jsdey  wrote:

>  I have a project photos that has a model Album.  Admin (/admin/photos/
> album/  page has a button "Add Album".  I want to write a custom page
> for that action but can't find the view that does the processing.  Any
> guidance would be appreciated.  Thanks.
>
> John
>
> --
> 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.



django-admin login doubt

2012-03-24 Thread dummyman dummyman
Hi,

Is there a way to prevent django asking username and password from
127.0.0.1:8000/admin or any other form in admin ?

-- 
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: Multiple Choice Quiz

2012-03-24 Thread jbr3
Babatunde,

Yes, that's basically the same idea. The questions would all be on the
same page, however, and I wouldn't incorporate the time limit. But,
that's mostly what I was thinking of.

On Mar 24, 3:08 am, Babatunde Akinyanmi  wrote:
> Hi jbr3,
> Check scrabala.com
> Is it similar to what you are working on?
>
> On 3/23/12, jbr3  wrote:
>
>
>
> > Hi again,
>
> > I've been trying to figure this out for awhile, but to no avail. I'll
> > try to list the problems I've had in understanding it.
>
> > 1. I'm not sure what the forms.py file should look like.
>
> > Going by Shawn's model, would it be something like:
>
> > " class GuessForm(ModelForm):
> >       class Meta:
> >           model= Guess
> >           exclude = ('user')     "
>
> > This gives me a dropdown list of possible answers, but no form changes
> > I've tried to make give me multiple radio buttons or multiple
> > checkboxes. Have I selected the wrong model to make the modelform
> > from ?
>
> > 2. I don't completely understand the concept of using Booleans. I've
> > added admin functionality to the app so I can add questions and
> > potential answers as well as select (using a checkbox) the correct
> > response. Based on the model Shawn provided, selecting one of the
> > checkboxes generated in admin makes that choice true and the others
> > false. The user's answer needs to be compared against these, but I
> > don't understand how I would achieve that. I assume I'm supposed to
> > set this up in the form, but I can't get the radio buttons or
> > checkboxes to work there. I can successfully submit an answer from the
> > dropdown, but I still have no idea how it would be compared to the
> > stored boolean value. Do I have to write more code for this ? And what
> > would the best way be to retrieve it ?
>
> > Also, in the examples I've seen, BooleanField() in forms involves
> > creating a list of choices in the form. But it doesn't seem like I
> > would need such a thing if I'm just using radio buttons whose value
> > will be checked against a changing option for each question. Yet I
> > can't really see how an alternative approach would work.
>
> > 3. I don't know what the template should look like. It seems like I
> > should be mixing the form fields with data passed directly from the
> > model by using views. In my view, I've set
> > "Question.objects.get(id=1)" to a variable. I've passed that to the
> > template. But I've also used "{{ form.as_p }}". That gives me the
> > possible answers that had been entered in the admin in the template.
> > But, the answers aren't generated as radio buttons with text next to
> > them. It seems like I would have to pass the actual text of the
> > answers using views (setting "variable.answer_set.all()  to another
> > variable and then passing it to the template) and then generate radio
> > buttons some other way. When I generated the buttons in the template,
> > though, the submission failed. I don't see how these could be checked
> > against the boolean value stored for the right answer. And, like I
> > said, I can't figure out how to make them work properly with the
> > form.
>
> > I know I've asked this already, but is it possible for anyone to show
> > some sample code so I can understand how this should be done using
> > Shawn's models. I've been trying to get this for awhile now, but I
> > still don't really understand it. I know there are about fifty
> > different questions here, but if anyone could help out in any way it
> > would be appreciated.
>
> > Thanks
>
> > On Mar 14, 11:36 pm, jbr3  wrote:
> >> Can anyone help me with some questions I still have about this ? I
> >> haven't had much experience with web programming, so trying to
> >> understand this is kind of challenging.
>
> >> 1. I created the models Shawn suggested. And I'm now able to add a
> >> question and possible answers to it in the admin area. Each possible
> >> answer has a checkbox next to it with the "Correct" label from the
> >> model. Does setting the correct response require anything more than
> >> selecting the appropriate checkbox and saving the question ?
>
> >> 2. I still don't understand how I'm supposed to combine these three
> >> models together in order to get the right output for the user. I've
> >> been trying different approaches in views.py, forms.py and my
> >> template. But I can't really figure out how this should be set up. I
> >> don't like to keep asking for such direct examples.
> >> But would anyone be able to provide kind of an abstract view based on
> >> the model Shawn provided.
>
> >> On Mar 11, 5:16 pm, jbr3  wrote:
>
> >> > Thanks for responding Shawn. I guess I was thinking that if I wanted
> >> > to save the user's responses and the correct answers a different model
> >> > would be needed for both.
>
> >> > On Mar 11, 4:11 pm, Shawn Milochik  wrote:
>
> >> > > I think I'd do this:
>
> >> > > 

Re: Accessing objects from a dictionary in templates

2012-03-24 Thread gowtham
Hi Samuel,
Thanks a ton for this detailed suggestion.  I was almost certain, the
solution i was trying is not the optimal. Now its very clear. Thanks very
very much. You made my weekend. I will be all busy backing up my database
and implementing what you suggested.

Initially after reading your reply, i wondered, how can database handle it
if there is no linking table. Especially, bulk of my data goes in using
perl uploader. I started this project from designing the database & loading
data first then adopting models from it. But, after reading one of your
links, (Behind the scenes, Django creates an intermediary join table to
represent the many-to-many relationship.) i am clear how it works.

I might even try to use .through to adopt exisiting linking tables. But,
will try NOT doing that as its a simple manytomany relationship as you
observed.

Once again, THANKs very much for educating me,
Gowthaman



On Sat, Mar 24, 2012 at 3:36 AM, Sam Lai  wrote:

> On 24 March 2012 09:29, gowtham  wrote:
> > Template tag filters like this (made one for each field in the library
> > object) helps me to get what i wanted But, that seems too silly to
> do...
> >
> > in template
> > {{ reslibdic|hash2libcode:res.result_id }}
> >
>
> I had the same thought as Reinout did, but after your clarification I
> realised you want to get something out of reslibdic by using another
> variable as the key. AFAIK, there is no in-built way of doing this.
>
> However, it is worth taking a step back and having a look at what
> you're trying to do.
>
> "I have two models (Library and Result) linked by a third linking
> model (libraryresult (has id, library_id and result_id fields FKeyed
> to respective tables). A many to many relationship."
>
> By the sounds of things, you have actually defined a third model,
> libraryresult, that links the Library and Result models together. That
> third model is unnecessary (unless you have other attributes to store
> with the link, which you don't seem to have - if you do, see
>
> https://docs.djangoproject.com/en/1.4/topics/db/models/#intermediary-manytomany
> ).
>
> If you simply define a ManyToManyField on the Result model pointing to
> the Library model, e.g.
>
> class Result(models.Model):
># ...
>libraries = models.ManyToManyField(Library)
>
> ... then you can get all the related libraries for a particular result
> by simply doing -
>
> r = Result.objects.get(pk=1)
> print r.libraries.all()
>
> You can do the same in the template. There is no need to build the
> reslibdic object.
>
> See
> https://docs.djangoproject.com/en/1.4/topics/db/models/#many-to-many-relationships
> for help defining the model, and
>
> https://docs.djangoproject.com/en/1.4/topics/db/queries/#many-to-many-relationships
> for help querying the related objects.
>
> > in template tag file:
> >
> > def hash2libcode(h,key):
> > if key in h:
> > return h[key].librarycode
> > else:
> > return None
> >
> > register.filter(hash2libcode)
> >
> > --
> > 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.
>
>


-- 
Gowthaman

Bioinformatics Systems Programmer.
SBRI, 307 West lake Ave N Suite 500
Seattle, WA. 98109-5219
Phone : LAB 206-256-7188 (direct).

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



[no subject]

2012-03-24 Thread William Slippey


-- 
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: Abridged summary of django-users@googlegroups.com - 45 Messages in 19 Topics

2012-03-24 Thread William Slippey
On Sat, Mar 24, 2012 at 9:22 AM,  wrote:

>   Today's Topic Summary
>
> Group: http://groups.google.com/group/django-users/topics
>
>- sql for Many To Many Field in existing django 
> model<#13644df8deb67955_group_thread_0>[1 Update]
>- problem with admin settings <#13644df8deb67955_group_thread_1> [2
>Updates]
>- Accessing objects from a dictionary in 
> templates<#13644df8deb67955_group_thread_2>[8 Updates]
>- Multiple Choice Quiz <#13644df8deb67955_group_thread_3> [2 Updates]
>- Filtering a second admin dropdown's contents based on the first
>dropdown's selection <#13644df8deb67955_group_thread_4> [1 Update]
>- Django FOrms <#13644df8deb67955_group_thread_5> [2 Updates]
>- serialize queryset metadata - what's the best 
> approach?<#13644df8deb67955_group_thread_6>[1 Update]
>- Pip install matplotlib error with 
> virtualenv<#13644df8deb67955_group_thread_7>[8 Updates]
>- ANNOUNCE: Django 1.4 released <#13644df8deb67955_group_thread_8> [4
>Updates]
>- Is it secure to have IDs show up in 
> URLs?<#13644df8deb67955_group_thread_9>[2 Updates]
>- ModelForms <#13644df8deb67955_group_thread_10> [3 Updates]
>- Django deployment practices -- do people use 
> setup.py?<#13644df8deb67955_group_thread_11>[1 Update]
>- Django log lines spamming syslog <#13644df8deb67955_group_thread_12>[3 
> Updates]
>- reverse urls on admin <#13644df8deb67955_group_thread_13> [1 Update]
>- Weird stacktrace coming from manage.py 
> test<#13644df8deb67955_group_thread_14>[2 Updates]
>- Django-1.4c2 logging issue on Snow 
> Leopard<#13644df8deb67955_group_thread_15>[1 Update]
>- Customizie admin views <#13644df8deb67955_group_thread_16> [1 Update]
>- Automatic indexes on foreign keys <#13644df8deb67955_group_thread_17>[1 
> Update]
>- Abridged summary of django-users@googlegroups.com - 27 Messages in
>14 Topics <#13644df8deb67955_group_thread_18> [1 Update]
>
>   sql for Many To Many Field in existing django 
> model
>
>Nikhil Verma  Mar 24 06:32PM +0530
>
>Hi
>
>I am able to create the field through in postgres.
>When i execute that sql statement :-
>
>CREATE TABLE "visit_visit_research" (
>"id" serial NOT NULL PRIMARY KEY,
>"visit_id" integer ...more
>
>   problem with admin 
> settings
>
>Swaroop Shankar V  Mar 24 12:03AM +0530
>
>Hello Sophia,
>
>I have made some changes to the structure of your project. Now it
>seems to
>be working. Mine is a linux machine, so am completely not sure if it
>would
>work on your widows machine, ...more
>
>
>Sophia  Mar 24 05:32AM -0700
>
>Thanks a lot Swaroop it finally works. I really appreciate your help.
>
>But could you please tell me what was wrong with my code I search
>through
>it and found a change in settings :
>...more
>
>   Accessing objects from a dictionary in 
> templates
>
>gowtham  Mar 23 12:56PM -0700
>
>Hi Everyone,
>I am trying to pass a dictionary with numerical as key and a object as
>value to my template...
>i construct it like this: ...more
>
>
>Reinout van Rees  Mar 23 09:41PM +0100
>
>On 23-03-12 20:56, gowtham wrote:
>
>> But, in template, rather than iterating over the dictionary (using
>for
>> and items) i would like to access them using keys.
>
>You can, can't you? {{ ...more
>
>
>gowtham  Mar 23 02:00PM -0700
>
>Hi Reinout,
>Thanks.
>
>But, i could not get it. It prints the primary key of the stored object
>rather than the object itself.
>
>Gowthaman
>
>
>--
>Gowthaman
>
>Bioinformatics Systems Programmer. ...more
>
>
>Reinout van Rees  Mar 23 11:07PM +0100
>
>On 23-03-12 22:00, gowtham wrote:
>
>> But, i could not get it. It prints the primary key of the stored
>object
>> rather than the object itself.
>
>Well, I don't know what's in the stored object. ...more
>
>
>gowtham  Mar 23 03:24PM -0700
>
>Yes, That is correct.
>
>Let me step back a bit and explain you what i am trying. It's quite
>possible i am doing the right thing.
>
>I have two models (Library and Result) linked by a third linking
>...more
>
>
>gowtham  Mar 23 03:25PM -0700
>
>sorry, I meant to say
>"It's quite possible i am NOT doing the right thing."
>
>
>
>
>
>
>
>
>
>--
>Gowthaman
>
>Bioinformatics Systems Programmer.
>SBRI, 307 West lake Ave N Suite 500 ...more
>
>
>gowtham  Mar 23 03:29PM -0700
>
>Template tag filters like 

Re: ANNOUNCE: Django 1.4 released

2012-03-24 Thread Brian Neal
On Friday, March 23, 2012 12:11:22 PM UTC-5, James Bennett wrote:
>
> Django 1.4 is finally here!
>
> For details, checkout the weblog:
>
> https://www.djangoproject.com/​weblog/2012/mar/23/14/
>
> And the release notes:
>
> https://docs.djangoproject.​com/en/dev/releases/1.4/
>

Great! Congratulations!

Now might be a good time to consider making a donation to the Django 
Software Foundation to show appreciation:

https://www.djangoproject.com/foundation/donate/

-BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/zRizCo0DcVQJ.
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: Pip install matplotlib error with virtualenv

2012-03-24 Thread darwin_tech
Yes, that is true. I set the virtualenv with --no-site-packages as I want 
a reproducible environment for my Django project. This should not mean that 
I cannot install matplotlib within the virtualenv though, surely?

Sam

On Friday, 23 March 2012 14:42:55 UTC-6, Reinout van Rees wrote:
>
> On 23-03-12 21:37, Reinout van Rees wrote:
> > On 23-03-12 18:51, darwin_tech wrote:
> >> the weird thing is that matplotlib works fine on my system. If I have a
> >> Django project running outside of virtualenv, there is no problem and
> >> matplotlib is on the pythonpath.
> >
> > One of virtualenv's options is to isolate you *completely* from the
> > system python. "virtualenv -s" or something like that.
>
> I checked, it is '--no-site-packages'.
>
>
> Reinout
>
> -- 
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.​nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
On Friday, 23 March 2012 14:42:55 UTC-6, Reinout van Rees wrote:
>
> On 23-03-12 21:37, Reinout van Rees wrote:
> > On 23-03-12 18:51, darwin_tech wrote:
> >> the weird thing is that matplotlib works fine on my system. If I have a
> >> Django project running outside of virtualenv, there is no problem and
> >> matplotlib is on the pythonpath.
> >
> > One of virtualenv's options is to isolate you *completely* from the
> > system python. "virtualenv -s" or something like that.
>
> I checked, it is '--no-site-packages'.
>
>
> Reinout
>
> -- 
> Reinout van Reeshttp://reinout.vanrees.org/
> rein...@vanrees.org 
> http://www.nelen-schuurmans.​nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/baJsLUq9es4J.
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: sql for Many To Many Field in existing django model

2012-03-24 Thread Nikhil Verma
Hi

I am able to create the field through in postgres.
When i execute that sql statement :-

CREATE TABLE "visit_visit_research" (
"id" serial NOT NULL PRIMARY KEY,
"visit_id" integer NOT NULL REFERENCES "visit_visit" ("id") DEFERRABLE
INITIALLY DEFERRED,
"research_id" integer NOT NULL REFERENCES "www_researchprotocol" ("id")
DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("visit_id", "research_id")
)
;

I get this :-

psql:db/2012-03-24_research_protocol.sql:7: NOTICE:  CREATE TABLE will
create implicit sequence "visit_visit_research_id_seq" for serial column "
visit_visit_research.id"
psql:db/2012-03-24_research_protocol.sql:7: NOTICE:  CREATE TABLE / PRIMARY
KEY will create implicit index "visit_visit_research_pkey" for table
"visit_visit_research"
psql:db/2012-03-24_research_protocol.sql:7: NOTICE:  CREATE TABLE / UNIQUE
will create implicit index "visit_visit_research_visit_id_key" for table
"visit_visit_research"
CREATE TABLE

So the field gets created but when i am going in django-admin in table
visit i am getting an error.It is not showing up two boxes i mean the many
to many widget which django displays.

This is the error

Exception Type: DatabaseError at /admin/visit/visit/20/
Exception Value: column visit_visit_research.researchprotocol_id does not
exist
LINE 1: ...visit_research" ON ("www_researchprotocol"."id" = "visit_vis...
 ^

Any help will be appreciated.

Thanks in advance.


On Thu, Mar 22, 2012 at 6:26 PM, Joel Goldstick wrote:

> On Thu, Mar 22, 2012 at 6:55 AM, Nikhil Verma 
> wrote:
> > Hi All
> >
> > I want to add a ManyToManyField  to an existing django model.
> >
> > I can use sql app_name and see the statement.
> >
> > My models
> >
> > Class Visit(modes.Model):
> >   x = something
> >   . ..
> >   .. and so on
> >  # finally Here i want to add that field research protol
> >  research_protocol  =
> > models.ManyToManyField(ResearchProtocol,blank=True)
> >
> >
> >
> > class ResearchProtocol(models.Model):
> > title = models.CharField(max_length=30)
> > description = models.TextField()
> > start_date = models.DateField(_("Date Started"))
> > end_date = models.DateField(_("Date Completed"))
> >
> > def __unicode__(self):
> > return '%s' % self.title
> >
> >
> >
> > So i made an sql statement like this:-
> >
> > CREATE TABLE "visit_visit_research_protocols"
> > (
> > "id" integer NOT NULL PRIMARY KEY,
> >
> > "visit_id" integer NOT NULL REFERENCES "visit_visit" ("id")
> DEFERRABLE
> > INITIALLY DEFERRED,
> > "research_protocols_id" varchar(80) NOT NULL REFERENCES
> > "www_researchprotocol" ("title") DEFERRABLE INITIALLY DEFERRED,
> > UNIQUE ("visit_id","research_protocols_id")
> > );
> >
> > The dbshell says:-
> > psql:db/2012-03-22_research_id.sql:8: NOTICE:  CREATE TABLE / PRIMARY KEY
> > will create implicit index "visit_visit_research_protocols_pkey" for
> table
> > "visit_visit_research_protocols"
> > psql:db/2012-03-22_research_id.sql:8: NOTICE:  CREATE TABLE / UNIQUE will
> > create implicit index
> > "visit_visit_research_protocol_visit_id_research_protocols_i_key" for
> table
> > "visit_visit_research_protocols"
> > psql:db/2012-03-22_research_id.sql:8: ERROR:  there is no unique
> constraint
> > matching given keys for referenced table "www_researchprotocol"
> >
> >
> >
> > What mistake i am doing  ?
> >
> > Thanks in advance.
> >
> >
> > --
> > Regards
> > Nikhil Verma
> > +91-958-273-3156
> >
> > --
> > 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 can't add the many to many relationship after you already have the
> model with django.  See this:
>
> http://stackoverflow.com/questions/830130/adding-a-field-to-an-existing-django-model
> That answer points to South, which I have played with but am not
> proficient yet.  Another thought is to create a new model, identical
> to your present one, but include the many2many and dbsync that.  If it
> works, copy your data from your old model into your new model.
>
>
> --
> Joel Goldstick
>
> --
> 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.
>
>


-- 
Regards
Nikhil Verma
+91-958-273-3156

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to 

Re: Accessing objects from a dictionary in templates

2012-03-24 Thread Sam Lai
On 24 March 2012 09:29, gowtham  wrote:
> Template tag filters like this (made one for each field in the library
> object) helps me to get what i wanted But, that seems too silly to do...
>
> in template
> {{ reslibdic|hash2libcode:res.result_id }}
>

I had the same thought as Reinout did, but after your clarification I
realised you want to get something out of reslibdic by using another
variable as the key. AFAIK, there is no in-built way of doing this.

However, it is worth taking a step back and having a look at what
you're trying to do.

"I have two models (Library and Result) linked by a third linking
model (libraryresult (has id, library_id and result_id fields FKeyed
to respective tables). A many to many relationship."

By the sounds of things, you have actually defined a third model,
libraryresult, that links the Library and Result models together. That
third model is unnecessary (unless you have other attributes to store
with the link, which you don't seem to have - if you do, see
https://docs.djangoproject.com/en/1.4/topics/db/models/#intermediary-manytomany).

If you simply define a ManyToManyField on the Result model pointing to
the Library model, e.g.

class Result(models.Model):
# ...
libraries = models.ManyToManyField(Library)

... then you can get all the related libraries for a particular result
by simply doing -

r = Result.objects.get(pk=1)
print r.libraries.all()

You can do the same in the template. There is no need to build the
reslibdic object.

See 
https://docs.djangoproject.com/en/1.4/topics/db/models/#many-to-many-relationships
for help defining the model, and
https://docs.djangoproject.com/en/1.4/topics/db/queries/#many-to-many-relationships
for help querying the related objects.

> in template tag file:
>
> def hash2libcode(h,key):
>     if key in h:
>         return h[key].librarycode
>     else:
>         return None
>
> register.filter(hash2libcode)
>
> --
> 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: Multiple Choice Quiz

2012-03-24 Thread Babatunde Akinyanmi
Hi jbr3,
Check scrabala.com
Is it similar to what you are working on?

On 3/23/12, jbr3  wrote:
> Hi again,
>
> I've been trying to figure this out for awhile, but to no avail. I'll
> try to list the problems I've had in understanding it.
>
> 1. I'm not sure what the forms.py file should look like.
>
> Going by Shawn's model, would it be something like:
>
> " class GuessForm(ModelForm):
>   class Meta:
>   model= Guess
>   exclude = ('user') "
>
> This gives me a dropdown list of possible answers, but no form changes
> I've tried to make give me multiple radio buttons or multiple
> checkboxes. Have I selected the wrong model to make the modelform
> from ?
>
> 2. I don't completely understand the concept of using Booleans. I've
> added admin functionality to the app so I can add questions and
> potential answers as well as select (using a checkbox) the correct
> response. Based on the model Shawn provided, selecting one of the
> checkboxes generated in admin makes that choice true and the others
> false. The user's answer needs to be compared against these, but I
> don't understand how I would achieve that. I assume I'm supposed to
> set this up in the form, but I can't get the radio buttons or
> checkboxes to work there. I can successfully submit an answer from the
> dropdown, but I still have no idea how it would be compared to the
> stored boolean value. Do I have to write more code for this ? And what
> would the best way be to retrieve it ?
>
> Also, in the examples I've seen, BooleanField() in forms involves
> creating a list of choices in the form. But it doesn't seem like I
> would need such a thing if I'm just using radio buttons whose value
> will be checked against a changing option for each question. Yet I
> can't really see how an alternative approach would work.
>
> 3. I don't know what the template should look like. It seems like I
> should be mixing the form fields with data passed directly from the
> model by using views. In my view, I've set
> "Question.objects.get(id=1)" to a variable. I've passed that to the
> template. But I've also used "{{ form.as_p }}". That gives me the
> possible answers that had been entered in the admin in the template.
> But, the answers aren't generated as radio buttons with text next to
> them. It seems like I would have to pass the actual text of the
> answers using views (setting "variable.answer_set.all()  to another
> variable and then passing it to the template) and then generate radio
> buttons some other way. When I generated the buttons in the template,
> though, the submission failed. I don't see how these could be checked
> against the boolean value stored for the right answer. And, like I
> said, I can't figure out how to make them work properly with the
> form.
>
> I know I've asked this already, but is it possible for anyone to show
> some sample code so I can understand how this should be done using
> Shawn's models. I've been trying to get this for awhile now, but I
> still don't really understand it. I know there are about fifty
> different questions here, but if anyone could help out in any way it
> would be appreciated.
>
> Thanks
>
>
>
>
> On Mar 14, 11:36 pm, jbr3  wrote:
>> Can anyone help me with some questions I still have about this ? I
>> haven't had much experience with web programming, so trying to
>> understand this is kind of challenging.
>>
>> 1. I created the models Shawn suggested. And I'm now able to add a
>> question and possible answers to it in the admin area. Each possible
>> answer has a checkbox next to it with the "Correct" label from the
>> model. Does setting the correct response require anything more than
>> selecting the appropriate checkbox and saving the question ?
>>
>> 2. I still don't understand how I'm supposed to combine these three
>> models together in order to get the right output for the user. I've
>> been trying different approaches in views.py, forms.py and my
>> template. But I can't really figure out how this should be set up. I
>> don't like to keep asking for such direct examples.
>> But would anyone be able to provide kind of an abstract view based on
>> the model Shawn provided.
>>
>> On Mar 11, 5:16 pm, jbr3  wrote:
>>
>> > Thanks for responding Shawn. I guess I was thinking that if I wanted
>> > to save the user's responses and the correct answers a different model
>> > would be needed for both.
>>
>> > On Mar 11, 4:11 pm, Shawn Milochik  wrote:
>>
>> > > I think I'd do this:
>>
>> > > Models:
>>
>> > >      Question
>> > >          question text
>>
>> > >      Answer
>> > >          question foreign key
>> > >          answer text
>> > >          correct (boolean)
>>
>> > >      Guess
>> > >          user foreign key
>> > >          answer foreign key
>>
>> > > That should be all you need (along with the User model or your own
>> > > method of tracking unique users without forcing them to