Re: Javascript in external file not working

2012-11-26 Thread Bill Beal
I think {{STATIC_URL}} should have spaces, like {{ STATIC_URL }}.

On Mon, Nov 26, 2012 at 6:04 PM, Loai Ghoraba  wrote:

> Hi all
>
> When I have a script like this:
>  window.onload=function f(){}  it is working fine. but
> when I create an external js file and put it within the static directory,
> and call the function like this
> 
>  window.onload=f 
>
> It is not working at all. (by the way the url is mapped correctly to the
> js file "I tested it via viewing the source of the web page")
>
> Any idea?
>
> --
> 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/-/m9Dv6qeozQQJ.
> 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.



set_expiry() auto logout on browser close

2012-11-24 Thread Bill Beal
Hi All,

I'm trying to log the user out automatically when the browser closes.  I
call 'request.session.set_expiry(0)' on login and I'm using
'SESSION_EXPIRE_AT_BROWSER_CLOSE = True' in my settings.  It's not
happening.  The 'How to use sessions' doc (1.4) says this call makes the
session cookie expire when the user's web browser is closed.  When I
abandon my logged-in session and come back the next day without logging in,
I'm still logged in!  What's the mechanism here?  Doesn't 'session expired'
mean logged out?  Do I need to install middleware such as
django-session-security?

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



Using email instead of username for registration and login

2012-09-24 Thread Bill Beal
Hi all,

I want to use the email address as the username for registration and login. 
 I'm using django-registration for 2-stage registration.  I'm looking for 
an easier way than what I've come up with so far.  I can modify 
registration and activation, but then django.contrib.auth.views.login has a 
30-character limit on the username.  I'm not looking forward to making 
username act like an email address.  Any quick fixes?

-- 
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/-/E4GTF1wAPZ8J.
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: How to separate data having the same model but belonging to different users?

2012-09-22 Thread Bill Beal
I don't think so.  The question actually had a different point, namely 
"When I put a decorator on my model, how do I keep the original name for 
the table?"  It didn't specify what the decorator does.  There is a link to 
a doc on proxy models, but it appears that they create multiple tables.

I should think that if you have a foreign key to the department in all 
tables that must be segregated by department, you could create a decorator 
that would apply a filter with the department key.  But I don't know how to 
do it.

On Saturday, September 22, 2012 11:23:16 PM UTC-4, Rohit Banga wrote:
>
> Thats interesting Bill.
> Are you talking about something like this?
>
> http://stackoverflow.com/questions/3276700/django-model-subclass-without-changing-database-name
>
> Thanks
> Rohit Banga
> http://iamrohitbanga.com/
>
>
> On Sat, Sep 22, 2012 at 8:15 PM, Bill Beal 
> > wrote:
>
>> Question for an expert from a newbie:  Could you decorate each model that 
>> has data that needs to be separated by departments?  If so, you wouldn't 
>> have to remember to code the department filter on each retrieval.
>>
>>
>> On Friday, September 21, 2012 10:06:35 PM UTC-4, Rohit Banga wrote:
>>
>>> Hi Dennis
>>> Thanks for summarizing the contents of the mails.
>>> Do you foresee any problems with the Model Inheritance scheme? At my end 
>>> I am stuck at getting a way to achieve dynamic polymorphism - which is 
>>> probably because I am new to Python.
>>>
>>> I can create a new subclass for every Department I add. manage.py 
>>> syncdb creates the new table for every new department I add. Now I want 
>>> to write the application logic agnostic of the specific department. I want 
>>> to load the appropriate subclass dynamically at runtime. I haven't been 
>>> able to do this right now.
>>> I can afford to create a new subclass everytime and run manage.py syndb 
>>> after that but cannot rewrite all the application logic all over again.
>>>
>>> I feel given the subclass name there should be an easy way in python to 
>>> get the subclass itself which I should use for the current user.
>>>
>>> At this point I should also mention there are a set of about 5-6 tables 
>>> (department being just one example) that I need to replicate for each new 
>>> department. I am thinking of doing it all via subclassing. That is I would 
>>> need to load as many subclass objects dynamically given the name of the 
>>> department.
>>> If I can get the set of subclasses to use with a not too ugly looking 
>>> code is it still a terrible idea?
>>>
>>> Thanks
>>> Rohit Banga
>>> http://iamrohitbanga.com/
>>>
>>>
>>> On Fri, Sep 21, 2012 at 9:34 PM, Dennis Lee Bieber >> > wrote:
>>>
>>>>  On Fri, 21 Sep 2012 17:54:06 -0400, Rohit Banga
>>>>  declaimed the following in
>>>> gmane.comp.python.django.user:
>>>>
>>>> > Thanks Nikolas. I think my example was not clear.
>>>> >
>>>> > But all the code is shared between the departments (another reason 
>>>> for you
>>>> > to say use the same tables!).
>>>> > I do not need to have the explicit department name in the code. I 
>>>> don't
>>>> > know the name of the departments yet! (It is just a metaphor)
>>>> > I just want to add behavior like PhysicsDepartment.objects.**filter() 
>>>> or
>>>> > create(), save()  anywhere I want.
>>>> > I want to work with the base class while loading the data from the 
>>>> subclass
>>>> > at runtime. Simple polymorphism but with different database tables in 
>>>> the
>>>> > backend.
>>>> >
>>>>
>>>> I expect that over 95% of the responses will all emphasize using
>>>> single set of tables, and a filter by the department (which is retrieved
>>>> from the log-in authorization information)
>>>>
>>>> Anything else means you have to somehow dynamically:
>>>>
>>>> 1)  use one database for authorization and; somehow OPEN a 
>>>> department
>>>> database connection that the models will hook into instead of using a
>>>> "load-time" database. That probably means you have to replace the Django
>>>> database connection system with one that you call at run-time. IOW, you
>>>> do not have a database configured

Re: How to separate data having the same model but belonging to different users?

2012-09-22 Thread Bill Beal
Question for an expert from a newbie:  Could you decorate each model that 
has data that needs to be separated by departments?  If so, you wouldn't 
have to remember to code the department filter on each retrieval.

On Friday, September 21, 2012 10:06:35 PM UTC-4, Rohit Banga wrote:
>
> Hi Dennis
> Thanks for summarizing the contents of the mails.
> Do you foresee any problems with the Model Inheritance scheme? At my end I 
> am stuck at getting a way to achieve dynamic polymorphism - which is 
> probably because I am new to Python.
>
> I can create a new subclass for every Department I add. manage.py syncdb 
> creates the new table for every new department I add. Now I want to write 
> the application logic agnostic of the specific department. I want to load 
> the appropriate subclass dynamically at runtime. I haven't been able to do 
> this right now.
> I can afford to create a new subclass everytime and run manage.py syndb 
> after that but cannot rewrite all the application logic all over again.
>
> I feel given the subclass name there should be an easy way in python to 
> get the subclass itself which I should use for the current user.
>
> At this point I should also mention there are a set of about 5-6 tables 
> (department being just one example) that I need to replicate for each new 
> department. I am thinking of doing it all via subclassing. That is I would 
> need to load as many subclass objects dynamically given the name of the 
> department.
> If I can get the set of subclasses to use with a not too ugly looking code 
> is it still a terrible idea?
>
> Thanks
> Rohit Banga
> http://iamrohitbanga.com/
>
>
> On Fri, Sep 21, 2012 at 9:34 PM, Dennis Lee Bieber 
> 
> > wrote:
>
>> On Fri, 21 Sep 2012 17:54:06 -0400, Rohit Banga
>> > declaimed the following in
>> gmane.comp.python.django.user:
>>
>> > Thanks Nikolas. I think my example was not clear.
>> >
>> > But all the code is shared between the departments (another reason for 
>> you
>> > to say use the same tables!).
>> > I do not need to have the explicit department name in the code. I don't
>> > know the name of the departments yet! (It is just a metaphor)
>> > I just want to add behavior like PhysicsDepartment.objects.filter() or
>> > create(), save()  anywhere I want.
>> > I want to work with the base class while loading the data from the 
>> subclass
>> > at runtime. Simple polymorphism but with different database tables in 
>> the
>> > backend.
>> >
>>
>> I expect that over 95% of the responses will all emphasize using
>> single set of tables, and a filter by the department (which is retrieved
>> from the log-in authorization information)
>>
>> Anything else means you have to somehow dynamically:
>>
>> 1)  use one database for authorization and; somehow OPEN a department
>> database connection that the models will hook into instead of using a
>> "load-time" database. That probably means you have to replace the Django
>> database connection system with one that you call at run-time. IOW, you
>> do not have a database configured in the normal manner -- but EVERY
>> Django function that issues an SQL operation would have to do something
>> like:
>>
>> if not dbConnection:
>> dbName = authuserdepartmentname
>> dbConnection = whateverapi(database=dbName,...)
>>
>> where dbConnection is whatever Django normally uses to track the
>> database connection.
>>
>>
>> 2)  not use Django models defined at build time (ie, in code), but
>> dynamically build the models at run-time so that you can specify the
>> table name when accessed (sort of using code templates into which you
>> substitute the needed table names which are then imported later -- good
>> luck getting Django to recognize the validity of the models).
>>
>>
>> 3)  operate separate "servers" for each department. Each server would
>> have its own location for datafiles, but you can probably share the
>> application code via soft-links or maybe even one shared code directory.
>> This is workable for those databases that allow connections defined by
>> file name/path (SQLite, embedded Firebird) but not for those using a
>> dedicated database server (MySQL, PostgreSQL) -- because the file "name"
>> will be fixed, but the data path would be relative to the "web server"
>> URL. Of course, if you have many departments, you end up with many
>> "servers" on different ports:
>>
>> http://server.localhost:8080/   Physics
>> http://server.localhost:8081/   Mathematics
>>
>> or your server on port 80 rewrites URLs
>>
>> http://physics.server.localhost/ => server.localhost:8080
>> http://mathematics.server.localhost/ => server.localhost:8081
>> or
>> http://physics.server.localhost/ => 
>> http://server.localhost/physics
>>
>> where the directory structure is something like
>>
>> physics/
>> app1-> softlink to  common/app1
>> data/
>> sqlite.db
>>
>> ma

Re: runserver error: "No module named app3"

2012-08-24 Thread Bill Beal
I am using pip, and once I tried virtualenv without understanding it and it
worked.  There's a kind of knowledge that I call "who's on first"
knowledge: you know what comes next but you don't know why.

On Thu, Aug 23, 2012 at 6:29 PM, Alexis Bellido wrote:

> I'd suggest you decouple your apps from your projects. If you want to have
> everything under the same tree you could, I don't do it that way though.
>
> You could have a tree like this:
>
> /home/user
> --proj
> proj (this contains settings.py in Django 1.4)
> app1
> app2
> --app3
>
> You already noticed that Django 1.4 has an inner proj directory which
> contains settings.py but notice the outer directory doesn't need to be
> called proj, you could rename it and everything will work. In fact, you
> could change the inner directory name too if you update the corresponding
> variables in settings.py (ROOT_URLCONF and WSGI_APPLICATION are the two
> ones that come to mind).
>
> In my example tree I have app1 and app2 under the outer proj and at the
> same level with the inner proj and I have app3 at the same level with the
> outer proj but that doesn't matter much because as long as you have app1,
> app2 and app3 in your PYTHONPATH you will able to do something like this:
>
> INSTALLED_APPS = (
> ...
> ...
> 'app1',
> 'app2',
> 'app3',
> )
>
> If you are not using virtualenv and pip yet you should, it helps a lot.
>
> Notice you don't need to include use proj (such as in 'proj.app1') and
> this is the way to go if you want to reuse your apps in other projects.
>
> Good luck!
>
> On Wednesday, August 22, 2012 6:16:15 PM UTC-3, Bill Beal wrote:
>>
>> Hi all,
>>
>> I have a Django project with apps that works OK on a Mac with Django 1.3
>> and Python 2.6, and I'm trying to move it to a Linux box with Django 1.4
>> and Python 2.7.  I created an empty project 'proj' with apps 'app1',
>> 'app2', 'app3' on the Linux system and carefully merged settings.py,
>> urls.py etc. with the initial files that were created.  When I run 'python
>> manage.py runserver' it says "Error: no module named app3" if app3 is the
>> last in the list of installed apps (see below), but if I swap app2 and app3
>> it claims app2 (now the last one in the list) is missing.  The error
>> message seems to be lying to me, and I don't know where to look for the
>> error.  In the settings.py file I have
>>
>> INSTALLED_APPS = (
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.sites',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',
>> # Uncomment the next line to enable the admin:
>> 'django.contrib.admin',
>> # Uncomment the next line to enable admin documentation:
>> 'django.contrib.admindocs',
>> 'django.django-adminfiles',
>> 'proj.app1',
>> 'proj.app2',
>> 'proj.app3',
>> )
>>
>> I've looked around for anything on "Error: No module named xxx", but
>> haven't found any that seem to relate to this behavior.  Has anyone seen
>> this kind of error dependent on the order of the apps?  Is there any way I
>> can force a more informative error?  I tried adding an empty module name at
>> the end, and it gave me an error trace, but I couldn't figure out anything
>> from  it.  My directory tree looks like this:
>>
>> proj/
>> manage.py
>> proj/proj/
>> __init__.py
>> settings.py
>> urls.py
>> wsgi.py
>> proj/app1/
>> __init__.py
>> forms.py
>> models.py
>> tests.py
>> views.py
>> proj/app2/
>> __init__.py
>> forms.py
>> models.py
>> tests.py
>> views.py
>> proj/app3/
>> __init__.py
>> forms.py
>> models.py
>> tests.py
>> views.py
>> proj/templates/
>> . . .
>>
>> Django 1.4 seems to have a second proj directory under the first level
>> proj directory.  I didn't see this in 1.3.
>>
>>  --
> 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/-/pdq0xqjRk_QJ.
>
> 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: runserver error: "No module named app3"

2012-08-22 Thread Bill Beal
Sorry, MELVYN.

On Wednesday, August 22, 2012 11:53:44 PM UTC-4, Bill Beal wrote:
>
> Thanks, Melvin!  That did it.  On to the next error!
>
>
> On Wednesday, August 22, 2012 5:16:15 PM UTC-4, Bill Beal wrote:
>>
>> Hi all,
>>
>> I have a Django project with apps that works OK on a Mac with Django 1.3 
>> and Python 2.6, and I'm trying to move it to a Linux box with Django 1.4 
>> and Python 2.7.  I created an empty project 'proj' with apps 'app1', 
>> 'app2', 'app3' on the Linux system and carefully merged settings.py, 
>> urls.py etc. with the initial files that were created.  When I run 'python 
>> manage.py runserver' it says "Error: no module named app3" if app3 is the 
>> last in the list of installed apps (see below), but if I swap app2 and app3 
>> it claims app2 (now the last one in the list) is missing.  The error 
>> message seems to be lying to me, and I don't know where to look for the 
>> error.  In the settings.py file I have
>>
>> INSTALLED_APPS = (
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.sites',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',
>> # Uncomment the next line to enable the admin:
>> 'django.contrib.admin',
>> # Uncomment the next line to enable admin documentation:
>> 'django.contrib.admindocs',
>> 'django.django-adminfiles',
>> 'proj.app1',
>> 'proj.app2',
>> 'proj.app3',
>> )
>>
>> I've looked around for anything on "Error: No module named xxx", but 
>> haven't found any that seem to relate to this behavior.  Has anyone seen 
>> this kind of error dependent on the order of the apps?  Is there any way I 
>> can force a more informative error?  I tried adding an empty module name at 
>> the end, and it gave me an error trace, but I couldn't figure out anything 
>> from  it.  My directory tree looks like this:
>>
>> proj/
>> manage.py
>> proj/proj/
>> __init__.py
>> settings.py
>> urls.py
>> wsgi.py
>> proj/app1/
>> __init__.py
>> forms.py
>> models.py
>> tests.py
>> views.py
>> proj/app2/
>> __init__.py
>> forms.py
>> models.py
>> tests.py
>> views.py
>> proj/app3/
>> __init__.py
>> forms.py
>> models.py
>> tests.py
>> views.py
>> proj/templates/
>> . . .
>>
>> Django 1.4 seems to have a second proj directory under the first level 
>> proj directory.  I didn't see this in 1.3.
>>
>>

-- 
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/-/pgyDVWZFwdoJ.
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: runserver error: "No module named app3"

2012-08-22 Thread Bill Beal
Thanks, Melvin!  That did it.  On to the next error!


On Wednesday, August 22, 2012 5:16:15 PM UTC-4, Bill Beal wrote:
>
> Hi all,
>
> I have a Django project with apps that works OK on a Mac with Django 1.3 
> and Python 2.6, and I'm trying to move it to a Linux box with Django 1.4 
> and Python 2.7.  I created an empty project 'proj' with apps 'app1', 
> 'app2', 'app3' on the Linux system and carefully merged settings.py, 
> urls.py etc. with the initial files that were created.  When I run 'python 
> manage.py runserver' it says "Error: no module named app3" if app3 is the 
> last in the list of installed apps (see below), but if I swap app2 and app3 
> it claims app2 (now the last one in the list) is missing.  The error 
> message seems to be lying to me, and I don't know where to look for the 
> error.  In the settings.py file I have
>
> INSTALLED_APPS = (
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.sites',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> # Uncomment the next line to enable the admin:
> 'django.contrib.admin',
> # Uncomment the next line to enable admin documentation:
> 'django.contrib.admindocs',
> 'django.django-adminfiles',
> 'proj.app1',
> 'proj.app2',
> 'proj.app3',
> )
>
> I've looked around for anything on "Error: No module named xxx", but 
> haven't found any that seem to relate to this behavior.  Has anyone seen 
> this kind of error dependent on the order of the apps?  Is there any way I 
> can force a more informative error?  I tried adding an empty module name at 
> the end, and it gave me an error trace, but I couldn't figure out anything 
> from  it.  My directory tree looks like this:
>
> proj/
> manage.py
> proj/proj/
> __init__.py
> settings.py
> urls.py
> wsgi.py
> proj/app1/
> __init__.py
> forms.py
> models.py
> tests.py
> views.py
> proj/app2/
> __init__.py
> forms.py
> models.py
> tests.py
> views.py
> proj/app3/
> __init__.py
> forms.py
> models.py
> tests.py
> views.py
> proj/templates/
> . . .
>
> Django 1.4 seems to have a second proj directory under the first level 
> proj directory.  I didn't see this in 1.3.
>
>

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



runserver error: "No module named app3"

2012-08-22 Thread Bill Beal
Hi all,

I have a Django project with apps that works OK on a Mac with Django 1.3 
and Python 2.6, and I'm trying to move it to a Linux box with Django 1.4 
and Python 2.7.  I created an empty project 'proj' with apps 'app1', 
'app2', 'app3' on the Linux system and carefully merged settings.py, 
urls.py etc. with the initial files that were created.  When I run 'python 
manage.py runserver' it says "Error: no module named app3" if app3 is the 
last in the list of installed apps (see below), but if I swap app2 and app3 
it claims app2 (now the last one in the list) is missing.  The error 
message seems to be lying to me, and I don't know where to look for the 
error.  In the settings.py file I have

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'django.django-adminfiles',
'proj.app1',
'proj.app2',
'proj.app3',
)

I've looked around for anything on "Error: No module named xxx", but 
haven't found any that seem to relate to this behavior.  Has anyone seen 
this kind of error dependent on the order of the apps?  Is there any way I 
can force a more informative error?  I tried adding an empty module name at 
the end, and it gave me an error trace, but I couldn't figure out anything 
from  it.  My directory tree looks like this:

proj/
manage.py
proj/proj/
__init__.py
settings.py
urls.py
wsgi.py
proj/app1/
__init__.py
forms.py
models.py
tests.py
views.py
proj/app2/
__init__.py
forms.py
models.py
tests.py
views.py
proj/app3/
__init__.py
forms.py
models.py
tests.py
views.py
proj/templates/
. . .

Django 1.4 seems to have a second proj directory under the first level proj 
directory.  I didn't see this in 1.3.

-- 
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/-/xrnaaTiYFOEJ.
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: django.shortcuts redirect doesn't pass argument

2012-08-05 Thread Bill Beal
I see that I had mixed the second and third ways of using 'redirect' in the
doc.  It seems to be working OK this way:

def upload1(request):
  . . .
  fout = 'tempfile.csv'
  return redirect('/isf/upload2/' + fout + '/')

def upload2(request, filename=None):
  . . .

with the following in urls.py:

(r'^app/upload2/(?P[A-Za-z0-9._-]+)/$', upload2),

Thanks.

I've been working on this while watching a live NASA feed of Curiosity's
landing on Mars.  Exciting!


On Sun, Aug 5, 2012 at 11:42 PM, Karen Tracey  wrote:

> On Sun, Aug 5, 2012 at 9:21 PM, forthfan  wrote:
>
>>
>> I'm trying to pass a filepath from one view to another by using
>> 'redirect' from django.shortcuts, but the argument is not getting passed.
>>  What am I doing wrong?
>>
>> def upload1(request):
>>   if request.method == 'POST':
>> form = UploadFileForm(request.POST, request.FILES)
>> if form.is_valid():
>>   filepath = request.FILES['file']
>>   return redirect('/app/upload2/', filepath=filepath)
>>
>
> You are passing the hardcoded url to redirect, which will be used as-is
> (per doc:
> https://docs.djangoproject.com/en/1.4/topics/http/shortcuts/#redirect).
> If you want the filepath kwarg to be used to construct the url specified in
> the redirect, you need to pass the name of the view (or url pattern) for
> the view.
>
> Karen
> --
> http://tracey.org/kmt/
>
>
>  --
> 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: django.shortcuts redirect doesn't pass argument

2012-08-05 Thread Bill Beal
My example is wrong, because filepath turns out to be an
'InMemoryUploadedFile' object.  But the problem remains the same because I
had a dummy filename string that I was trying to pass.  Actually the file
would be uploaded to the server to a local file in upload1, then the
filepath of the local file needs to be passed to upload2.

On Sun, Aug 5, 2012 at 9:21 PM, forthfan  wrote:

> Hi all,
>
> I'm trying to pass a filepath from one view to another by using 'redirect'
> from django.shortcuts, but the argument is not getting passed.  What am I
> doing wrong?
>
> def upload1(request):
>   if request.method == 'POST':
> form = UploadFileForm(request.POST, request.FILES)
> if form.is_valid():
>   filepath = request.FILES['file']
>   return redirect('/app/upload2/', filepath=filepath)
>
> def upload2(request, filepath=None):
>   if request.method == 'GET':
> if filepath:
> . . .
>
>  --
> 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/-/Bl7QVZZv7_MJ.
> 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: Read from an uploaded file and put data in a form for automatic Django validation

2012-07-30 Thread Bill Beal
This works:

In forms.py:

class UploadForm(forms.Form):
  name = forms.CharField(label='name')
  addr1 = forms.CharField(label='addr1')

Interactive:

>>> from django import *
>>> from app.forms import *
>>> d = {'name': 'Fibber McGee', 'addr1': '79 Wistful Vista'}
>>> form = UploadForm(d)
>>> form.is_bound
True
>>> form.is_valid()
True
>>> form.cleaned_data
{'name': u'Fibber McGee', 'addr1': u'79 Wistful Vista'}
>>>

I get a bound form from this, and Django does the validation for me.


On Sun, Jul 29, 2012 at 12:37 PM, Derek  wrote:

> Have a look at:
>
> http://stackoverflow.com/questions/6091965/django-upload-a-file-and-read-its-content-to-populate-a-model
>
>
>
> On Sunday, 29 July 2012 04:43:15 UTC+2, forthfan wrote:
>>
>> Hi all,
>>
>> Being lazy, I want Django to validate the stuff I read from an uploaded
>> file as if it were being posted.  Is there a nice way to do this?
>>
>  --
> 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/-/kGJ40VUVY90J.
>
> 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: REMOVE ME

2012-07-30 Thread Bill Beal
Andrew didn't ask the question, I did.  He apparently responded to my post
with his request to be removed.  Maybe I need to start over.

On Mon, Jul 30, 2012 at 1:33 AM, kenneth gonsalves
wrote:

> On Sun, 2012-07-29 at 14:32 +0800, Russell Keith-Magee wrote:
> > On Sun, Jul 29, 2012 at 1:56 PM, David Lam 
> > wrote:
> > > Try this from manage.py shell
> > >
> > DjangoMailListSubscription.objects.filter(email="
> collective...@gmail.com").delete()
> >
> > Andrew obviously wants to unsubscribe.
>
> are you sure - he has asked a question on validation of an uploaded
> file. He seems to have made a mistake on the subject line.
> --
> regards
> Kenneth Gonsalves
>
> --
> 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: How to call RegexValidator explicitly?

2012-05-26 Thread Bill Beal
Thanks!  I put it in today and it worked fine.

On May 24, 2012, at 9:10 AM, bruno desthuilliers wrote:

> On May 24, 4:30 am, forthfan  wrote:
>> 
>> from django import forms
>> from django.core.validators import *
>> 
>> class IdentForm(forms.Form):
>>   ident = forms.CharField()
>>   ident_type = forms.ChoiceField(choices=(
>>   ('EIN','Employer ID'),
>>   ('SSN','Social Security Number'),
>>   ))
>> 
>>   TYPE_CHOICES = (
>>   ('EIN','\d{2}-\d{7}'),
>>   ('SSN','\d{3}-\d{2}-\d{4}'),
>>   )
>> 
>>   def clean(self):
>> cleaned_data = super(IdentForm, self).clean()
>> ident = cleaned_data.get('ident')
>> ident_type = cleaned_data.get('ident_type')
> 
> Don't assume you'll have values for both fields in cleaned_data - they
> may have failed validation already.
> 
> 
>> regexp = TYPE_CHOICES[ident_type]
> 
> I assume you meant:
> 
>  regexp = self.TYPE_CHOICES[ident_type]
> 
> but it wont work since TYPE_CHOICES is a list of tuples, not a dict,
> so this should be:
> 
> 
>  regexp = dict(self.TYPE_CHOICES)[ident_type]
> 
>> RegexValidator([regexp]) # What's missing?
> 
> First, you have to get rid of the [] here - RegexpValidator expects
> either a string or compiled regexp as first argument.
> 
> Then once you have a validator instance, you have to call it (like you
> would call a function)
> 
>> # How do I pass ident to the validator?
> 
> As argument to the call.
> 
>> if ??: # Do I test for existence of error message?
> 
> Validators raise a django.core.exceptions.ValidationError
> 
>>   ident = ''
>> return cleaned_data
> 
> Rebinding the 'indent' symbol in the current namespace won't change
> the value (if any) of cleaned_data['ident']. You want to modify
> cleaned_data itself (and either set the erreor message manually in
> either ident and/or ident_type fields errors or reraise the
> ValidationError)
> 
> class IdentForm(forms.Form):
>  ident = forms.CharField()
>  ident_type = forms.ChoiceField(choices=(
>  ('EIN','Employer ID'),
>  ('SSN','Social Security Number'),
>  ))
> 
>  TYPE_CHOICES = (
>  ('EIN','\d{2}-\d{7}'),
>  ('SSN','\d{3}-\d{2}-\d{4}'),
>  )
> 
> # no need to reinstanciate validators on each call, we can as well
> # do the job here once for all
> TYPE_VALIDATORS = dict((key, RegexpValidator(regexp)) for key, regexp
> in TYPE_CHOICES)
> 
> def clean(self):
>cleaned_data = super(IdentForm, self).clean()
>ident = cleaned_data.get('ident', '')
>ident_type = cleaned_data.get('ident_type', '')
>if ident and ident_type:
>   # we assume that ident_type is ok here - if not there's
>   # a serious problem with forms.ChoiceField ;)
>   validate = self.TYPE_VALIDATORS[ident_type]
>   try:
>   validate(ident)
>   except ValidationError, e:
>   # doing the simplest thing here, so the error will appear
>   # in non-field errors. If you want to set the error on
>   # the ident and/or ident_type field(s), cf the FineManual:
>   # 
> https://docs.djangoproject.com/en/1.3/ref/forms/validation/#described-later
>   del self.cleaned_data['ident']
>   raise
> 
>return cleaned_data
> 
> HTH
> 
> -- 
> 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: Generating a list of available templates

2012-02-10 Thread Bill Beal
I know nothing, but here's what I did:

python manage.py shell
import os
from settings import TEMPLATE_DIRS
for x in TEMPLATE_DIRS:
  print x
  os.listdir(x)

It gave me a list of the files in the (each) template directory.

It looks like you already have a list of template directories in settings.py.

On Feb 10, 2012, at 4:51 PM, Patrick Wellever wrote:

> Thanks -- you must be on your way out the door now so I won't call, but 
> according to your area code it looks like we might be neighbors. ;) So 
> following the syntax I wrote out, what I still need to know is how do I get 
> to EVERY_DIRECTORY_DJANGO_LOOKS_FOR_TEMPLATES_IN. That's a variable that 
> represents wishful thinking on my part -- I don't actually know how to get an 
> iterable list of those directories.
> 
> There must be some way I can sort of hook into the logic Django uses to 
> construct a list of template directories...
> 
> - P
> 
> 
> On Fri, Feb 10, 2012 at 4:33 PM, Python_Junkie 
>  wrote:
> I think you have it with the syntax you just wrote down.
> 
> I will be available by phone until 4:45 if you want to call.
> 
> 781-...
> 
> On Feb 10, 4:19 pm, Patrick Wellever  wrote:
> >
> > I need something like:
> >
> > template_files = []
> > for dir in EVERY_DIRECTORY_DJANGO_LOOKS_FOR_TEMPLATES_IN:
> > template_files.extend(os.listdir(dir))
> 
> -- 
> 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: How to use a DB table for choices=tuples in ChoiceField?

2012-01-21 Thread Bill Beal
It looks like the Pythonic way is to create the list in
models.py and invoke it from forms.py.

Sorry about the heterogeneous names--some of
them match the document the requirements were
extracted from and others are more meaningful
to me.  The former were picked because we'll
need a requirements cross-reference and they'll
be easier to match up with the requirements.
And the dashes in place of spaces--most of the
code examples I see here are almost unreadable
because of leading spaces disappearing.
I saw one example of replacing all but the last
leading space with '-', and it was more readable.

Regards

On Fri, Jan 20, 2012 at 11:22 PM, Dennis Lee Bieber
wrote:

> On Fri, 20 Jan 2012 19:44:16 -0800 (PST), Bill Beal
>  wrote:
>
>Caveat: I've only looked at Django, but not in enough detail to be
> "expert"; my comments are based upon basic Python syntax/semantics (my
> apologies to the developers, but I work better with printed
> documentation and Django is too much of a moving target for the few
> books that did come out to be relevant four months later)
>
> >name 'scac_choicelist' is not defined at the marked
> >line in my form:
> >
> Which is true -- it is not defined at that point. (NOTE: your names
> don't really help understanding the purpose of the variables )
>
> >from django import forms
> >from django.forms.fields import ChoiceField
> >from myapp.models import *
> >
> >BOL_CODE_QUALIFIERS = (
> >  ('OB', 'Ocean Bill of Lading (OB)'),
> >  ('BM', 'House Bill of Lading (BM)'),
> >)
> >
> >class BolForm(forms.Form):
> >- scac = forms.ChoiceField(
> >- label=u'Ocean Carrier',
> >- choices=scac_choicelist()) ##
> >- bill_of_lading = forms.CharField(
> >- label=u'Bill of Lading #', max_length=50)
> >- bol_type = forms.ChoiceField(
> >- label=u'Type of B/L',
> >- choices=BOL_CODE_QUALIFIERS)
> >
> >Here's my model:
> >
> >from django.db import models
> >
> >class Scac(models.Model):
> >- code = models.CharField(max_length=4)
> >- name = models.CharField(max_length=60)
> >
> >- def __unicode__(self):
> >--- return self.code
> >
> >- def scac_choicelist():
> >--- q = Scac.objects.all()
> >--- scaclist = []
> >--- for x in q:
> >- scaclist.append((x.code, x.name))
> >- return scaclist
>
> Presuming the many "-"s represent indentation, "scac_choicelist" is
> a method of Scac. That means it should have at least one parameter: self
>
>def scac_choicelist(self):
>scaclist = []
>for item in self.objects.all():
>scaclist.append((item.code, item.name))
>return scaclist
>
> NOTE: based on your "-"s, your return statement is inside your loop, so
> you'd be returning after processing only one element.
>
>NOW... In the form module you need to reference an instance of the
> model! The method itself is not visible.
>
> >- scac = forms.ChoiceField(
> >- label=u'Ocean Carrier',
> >- choices=scac_choicelist()) ##
> >
>
> Something like:
>
>scac = forms.ChoiceField(   label=u"Ocean Carrier",
>
>  choices=Scac().scac_choicelist())
>
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> 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: How to use a DB table for choices=tuples in ChoiceField?

2012-01-20 Thread Bill Beal
Thank you, Dennis.  I'll study your answer.  I have to do this kind of
thing for a lot of different tables.  And I discovered another thing:  In
the template I was reading the table in again from the database!  Before my
problem was solved, I could populate the selection list from the DB table,
but then there were no valid choices when I got back to the view.

I'm getting to know Django just enough that I can sometimes answer
questions posted here, or at least make suggestions.

Regards

On Fri, Jan 20, 2012 at 11:22 PM, Dennis Lee Bieber
wrote:

> On Fri, 20 Jan 2012 19:44:16 -0800 (PST), Bill Beal
>  wrote:
>
>Caveat: I've only looked at Django, but not in enough detail to be
> "expert"; my comments are based upon basic Python syntax/semantics (my
> apologies to the developers, but I work better with printed
> documentation and Django is too much of a moving target for the few
> books that did come out to be relevant four months later)
>
> >name 'scac_choicelist' is not defined at the marked
> >line in my form:
> >
> Which is true -- it is not defined at that point. (NOTE: your names
> don't really help understanding the purpose of the variables )
>
> >from django import forms
> >from django.forms.fields import ChoiceField
> >from myapp.models import *
> >
> >BOL_CODE_QUALIFIERS = (
> >  ('OB', 'Ocean Bill of Lading (OB)'),
> >  ('BM', 'House Bill of Lading (BM)'),
> >)
> >
> >class BolForm(forms.Form):
> >- scac = forms.ChoiceField(
> >- label=u'Ocean Carrier',
> >- choices=scac_choicelist()) ##
> >- bill_of_lading = forms.CharField(
> >- label=u'Bill of Lading #', max_length=50)
> >- bol_type = forms.ChoiceField(
> >- label=u'Type of B/L',
> >- choices=BOL_CODE_QUALIFIERS)
> >
> >Here's my model:
> >
> >from django.db import models
> >
> >class Scac(models.Model):
> >- code = models.CharField(max_length=4)
> >- name = models.CharField(max_length=60)
> >
> >- def __unicode__(self):
> >--- return self.code
> >
> >- def scac_choicelist():
> >--- q = Scac.objects.all()
> >--- scaclist = []
> >--- for x in q:
> >- scaclist.append((x.code, x.name))
> >- return scaclist
>
> Presuming the many "-"s represent indentation, "scac_choicelist" is
> a method of Scac. That means it should have at least one parameter: self
>
>def scac_choicelist(self):
>scaclist = []
>for item in self.objects.all():
>scaclist.append((item.code, item.name))
>return scaclist
>
> NOTE: based on your "-"s, your return statement is inside your loop, so
> you'd be returning after processing only one element.
>
>NOW... In the form module you need to reference an instance of the
> model! The method itself is not visible.
>
> >- scac = forms.ChoiceField(
> >- label=u'Ocean Carrier',
> >- choices=scac_choicelist()) ##
> >
>
> Something like:
>
>scac = forms.ChoiceField(   label=u"Ocean Carrier",
>
>  choices=Scac().scac_choicelist())
>
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> 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: How to use a DB table for choices=tuples in ChoiceField?

2012-01-20 Thread Bill Beal
Well, I put the code in line, thus:

class BolForm(forms.Form):
- q = Scac.objects.all()
- scaclist = []
- for x in q:
--- scaclist.append((x.code, x.name))
- scac = forms.ChoiceField(
- label=u'Ocean Carrier', choices=scaclist)
- bill_of_lading = forms.CharField(
- label=u'Bill of Lading #', max_length=50)
- bol_type = forms.ChoiceField(
- label=u'Type of B/L', choices=BOL_CODE_QUALIFIERS)

It worked.  But is there a better way?

On Fri, Jan 20, 2012 at 10:44 PM, Bill Beal  wrote:

> Hi All,
>
> When I looked in the docs for how to fill in the
> "choices=" attribute for a ChoiceField in a form,
> I could only find static sets of tuples for examples.
> I need to use a table from the DB for the tuples.
> I thought I could make up the choice list myself
> from the table, but I'm getting a Name Error:
> name 'scac_choicelist' is not defined at the marked
> line in my form:
>
> from django import forms
> from django.forms.fields import ChoiceField
> from myapp.models import *
>
> BOL_CODE_QUALIFIERS = (
>  ('OB', 'Ocean Bill of Lading (OB)'),
>  ('BM', 'House Bill of Lading (BM)'),
> )
>
> class BolForm(forms.Form):
> - scac = forms.ChoiceField(
> - label=u'Ocean Carrier',
> - choices=scac_choicelist()) ##
> - bill_of_lading = forms.CharField(
> - label=u'Bill of Lading #', max_length=50)
> - bol_type = forms.ChoiceField(
> - label=u'Type of B/L',
> - choices=BOL_CODE_QUALIFIERS)
>
> Here's my model:
>
> from django.db import models
>
> class Scac(models.Model):
> - code = models.CharField(max_length=4)
> - name = models.CharField(max_length=60)
>
> - def __unicode__(self):
> --- return self.code
>
> - def scac_choicelist():
> --- q = Scac.objects.all()
> --- scaclist = []
> --- for x in q:
> - scaclist.append((x.code, x.name))
> - return scaclist
>
> I didn't know where to stick the scac_choicelist()
> code, so I put it with the model.
>
> Questions:
> 1. Is this a reasonable approach?  If not, what?
> 2. If so, how can I get scaclist into the form?
>
> I hope there is enough info here that my mistake
> is obvious to somebody.
>
> 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.



How to use a DB table for choices=tuples in ChoiceField?

2012-01-20 Thread Bill Beal
Hi All,

When I looked in the docs for how to fill in the
"choices=" attribute for a ChoiceField in a form,
I could only find static sets of tuples for examples.
I need to use a table from the DB for the tuples.
I thought I could make up the choice list myself
from the table, but I'm getting a Name Error:
name 'scac_choicelist' is not defined at the marked
line in my form:

from django import forms
from django.forms.fields import ChoiceField
from myapp.models import *

BOL_CODE_QUALIFIERS = (
  ('OB', 'Ocean Bill of Lading (OB)'),
  ('BM', 'House Bill of Lading (BM)'),
)

class BolForm(forms.Form):
- scac = forms.ChoiceField(
- label=u'Ocean Carrier',
- choices=scac_choicelist()) ##
- bill_of_lading = forms.CharField(
- label=u'Bill of Lading #', max_length=50)
- bol_type = forms.ChoiceField(
- label=u'Type of B/L',
- choices=BOL_CODE_QUALIFIERS)

Here's my model:

from django.db import models

class Scac(models.Model):
- code = models.CharField(max_length=4)
- name = models.CharField(max_length=60)

- def __unicode__(self):
--- return self.code

- def scac_choicelist():
--- q = Scac.objects.all()
--- scaclist = []
--- for x in q:
- scaclist.append((x.code, x.name))
- return scaclist

I didn't know where to stick the scac_choicelist()
code, so I put it with the model.

Questions:
1. Is this a reasonable approach?  If not, what?
2. If so, how can I get scaclist into the form?

I hope there is enough info here that my mistake
is obvious to somebody.

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.



Re: Please help with complex aggregation/annotation issue

2012-01-19 Thread Bill Beal
Each user nominates just one Messier number/image pair?

Do you need to keep track of the users to verify that each one votes only
once?


On Wed, Jan 18, 2012 at 4:03 AM, Salvatore Iovene <
salvatore.iov...@gmail.com> wrote:

> Hi,
> I apologize for the lousy title, but I really didn't know how to summarize
> the problem I'm facing. I have the following model:
>
> class MessierMarathon(models.Model):
> messier_number = models.IntegerField()
> image = models.ForeignKey(Image)
> nominations = models.IntegerField(default = 0)
> nominators = models.ManyToManyField(User, null=True)
>
> def __unicode__(self):
> return 'M %i' % self.messier_number
>
> class Meta:
> unique_together = ('messier_number', 'image')
> ordering = ('messier_number', 'nominations')
>
>
> A typical content for this model would be:
>
>Image A: 5 nominations for messier_number 1
>Image B: 4 nominations for messier_number 1
>Image C: 6 nominations for messier_number 2
>...and so on.
>
> I would like to formulate a query that returns me one image for each
> messier_number, picking the one with the most nominations. So, in the
> previous example, the query would return images A and C. The image B would
> not be returned because image A has more nominations for messier_number 1.
>
> The images returned must be sorted by messier_number, and of course may
> repeat. (An image might contain more that one Messier object, and get
> highest nomination counts for both).
>
> Can anybody please help with this?
> Thanks in advance,
>   Salvatore.
>
> --
> 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/-/GB-T19nk21cJ.
> 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: pseudo one-to-one

2012-01-16 Thread Bill Beal
How about this (or has it been mentioned already?): All children in one
table, all with FK to the parent.  One FK in the parent pointing to the one
special child.  Does there really have to be a one-to-one anywhere?
And I don't understand why anyone  needs to chain from child to child.  If
they are entered in chronological order, the IDs will be in numerical
order, or else you can add a field to order them.

On Mon, Jan 16, 2012 at 6:06 PM, Mike Dewhirst wrote:

> On 17/01/2012 4:13am, Jeff Heard wrote:
>
>> You might modify the manager to store historical entries in a
>> different table with the same structure.
>>
>
> I once built a work invoicing system like that where the work records got
> transferred from work_in_progress to work_invoiced as part of the invoicing
> process. It succeeded nicely because it was genuinely different information
> in different tables.
>
> This problem isn't quite the same and I'm reluctant to keep the same
> information in two places. There has to be a better way than multiple
> tables.
>
> Thanks Jeff
>
> Mike
>
>
>
>>
>>
>> On Jan 16, 2012, at 2:18 AM, Mike Dewhirst
>> wrote:
>>
>>  On 16/01/2012 5:19pm, Bill Beal wrote:
>>>
>>>> Why not have a child model that differs from the one-to-one child
>>>> model in that the parent key is now a foreign key to the parent?
>>>> When another child needs to replace the current one in the
>>>> one-to-one relationship, move the child to the second table where
>>>> there is a many-to-one relationship to the parent, then modify
>>>> the one-to-one child record.  If necessary, duplicate the current
>>>> one-to-one record in the many-to-one table.  Does this make
>>>> sense?
>>>>
>>>
>>> I understand what you mean but it feels a bit yukky. Thinking about
>>> it some more maybe I need a 'hidden' field which gets updated on
>>> saving based on the existence of a more modern child.
>>>
>>> Dunno.
>>>
>>> Thanks
>>>
>>> Mike
>>>
>>>
>>>
>>>> Bill Beal
>>>>
>>>> On Mon, Jan 16, 2012 at 12:55 AM, Mike
>>>> Dewhirstmailto:mi...@dewhirst.com.au>**>
>>>> wrote:
>>>>
>>>> I need a one-to-many to behave like a one-to-one.
>>>>
>>>> The parent instance of my model can only ever have one current
>>>> child instance of another model. Multiple child instances have to
>>>> exist and be kept for the historical record.
>>>>
>>>> The main benefit of one-to-one relationships is that they can be
>>>> mapped together (in the Admin) as an extension of the parent.
>>>>
>>>> In a view I suppose I can use a manager to filter the children
>>>> into a pseudo-one-to-one thingy but how do I do this in the
>>>> Admin?
>>>>
>>>> Maybe sort them into date order and only show one? Is there a
>>>> better way?
>>>>
>>>> Thanks for any help
>>>>
>>>> Mike
>>>>
>>>> -- 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
>>>> <mailto:django-users@**googlegroups.com >.
>>>> To unsubscribe from this
>>>> group, send email to 
>>>> django-users+unsubscribe@__goo**glegroups.com<http://googlegroups.com>
>>>> <mailto:django-users%**2bunsubscr...@googlegroups.com
>>>> **>. For more
>>>> options, visit this group at
>>>> http://groups.google.com/__**group/django-users?hl=en<http://groups.google.com/__group/django-users?hl=en>
>>>> <http://groups.google.com/**group/django-users?hl=en<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+unsubscribe@**googlegroups.com
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/**group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>>>> .
>>>>
>>>
>>> -- You received th

Re: Need "edit" and "delete" buttons on each line of a rendered table

2012-01-16 Thread Bill Beal
Thanks, now I don't have to do the hard work as a noob.

On Mon, Jan 16, 2012 at 9:23 AM, j_syk  wrote:

> This a good application for named urls with passing arguments.
>
> for example, given a urls.py containing
>
>url(r'^edit/(?P[0-9]+)/$', edit_item, name="edit_item"),
>
> in your template you can do this:
>
> {% for item in item_query %}
> 
>Edit
> 
> {% endfor %}
>
> Hope that helps! Named urls are the preferred DRY method too and so
> easy to use!
>
>
> On Jan 16, 8:04 am, Bill Beal  wrote:
> > Thanks, I'll try that.
> >
> > On Mon, Jan 16, 2012 at 8:58 AM, Szabo, Patrick (LNG-VIE) <
> >
> >
> >
> >
> >
> >
> >
> > patrick.sz...@lexisnexis.at> wrote:
> > > Hi,
> >
> > > I'm doing the exact same thing. What i do is i add the id of the
> object of
> > > a row to the url that the button is linking to.
> > > Then I use urls.py and views.py to identify that id and delete or add
> the
> > > object.
> >
> > > cheers
> >
> > > . . . . . . . . . . . . . . . . . . . . . . . . . .
> > > Ing. Patrick Szabo
> > >  XSLT Developer
> > > LexisNexis
> > > A-1030 Wien, Marxergasse 25
> >
> > > mailto:patrick.sz...@lexisnexis.at
> > > Tel.: 00431 534521573
> > > Fax: +43 1 534 52 146
> >
> > > -Ursprüngliche Nachricht-
> >
> > > Von: django-users@googlegroups.com [mailto:
> django-users@googlegroups.com]
> > > Im Auftrag von Bill Beal
> > > Gesendet: Montag, 16. Jänner 2012 14:55
> > > An: Django users
> > > Betreff: Need "edit" and "delete" buttons on each line of a rendered
> table
> >
> > > Hi All,
> >
> > > I'm trying to render a table and have an EDIT
> > > button and a DELETE button on each line, like:
> >
> > > ID numberID typeEDITDELETE
> >
> > > and identify which line is to be EDITed
> > > or DELETEd.  I tried to create a unique name
> > > for each button, like:
> >
> > >  > > value="EDIT" />
> >
> > > but the template language won't let me add.
> > > Is there a simpler way to know which line
> > > the submit came from, that works?
> > > Or even a complicated way that works?
> >
> > > Bill Beal
> >
> > > --
> > > 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: Need "edit" and "delete" buttons on each line of a rendered table

2012-01-16 Thread Bill Beal
Thanks, I'll try that.

On Mon, Jan 16, 2012 at 8:58 AM, Szabo, Patrick (LNG-VIE) <
patrick.sz...@lexisnexis.at> wrote:

> Hi,
>
> I'm doing the exact same thing. What i do is i add the id of the object of
> a row to the url that the button is linking to.
> Then I use urls.py and views.py to identify that id and delete or add the
> object.
>
> cheers
>
>
> . . . . . . . . . . . . . . . . . . . . . . . . . .
> Ing. Patrick Szabo
>  XSLT Developer
> LexisNexis
> A-1030 Wien, Marxergasse 25
>
> mailto:patrick.sz...@lexisnexis.at
> Tel.: 00431 534521573
> Fax: +43 1 534 52 146
>
>
> -Ursprüngliche Nachricht-
>
> Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com]
> Im Auftrag von Bill Beal
> Gesendet: Montag, 16. Jänner 2012 14:55
> An: Django users
> Betreff: Need "edit" and "delete" buttons on each line of a rendered table
>
> Hi All,
>
> I'm trying to render a table and have an EDIT
> button and a DELETE button on each line, like:
>
> ID numberID typeEDITDELETE
>
> and identify which line is to be EDITed
> or DELETEd.  I tried to create a unique name
> for each button, like:
>
>  value="EDIT" />
>
> but the template language won't let me add.
> Is there a simpler way to know which line
> the submit came from, that works?
> Or even a complicated way that works?
>
> Bill Beal
>
> --
> 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.



Need "edit" and "delete" buttons on each line of a rendered table

2012-01-16 Thread Bill Beal
Hi All,

I'm trying to render a table and have an EDIT
button and a DELETE button on each line, like:

ID numberID typeEDITDELETE

and identify which line is to be EDITed
or DELETEd.  I tried to create a unique name
for each button, like:



but the template language won't let me add.
Is there a simpler way to know which line
the submit came from, that works?
Or even a complicated way that works?

Bill Beal

-- 
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: pseudo one-to-one

2012-01-15 Thread Bill Beal
Why not have a child model that differs from the one-to-one child model in
that the parent key is now a foreign key to the parent?  When another child
needs to replace the current one in the one-to-one relationship, move the
child to the second table where there is a many-to-one relationship to the
parent, then modify the one-to-one child record.  If necessary, duplicate
the current one-to-one record in the many-to-one table.  Does this make
sense?

Bill Beal

On Mon, Jan 16, 2012 at 12:55 AM, Mike Dewhirst wrote:

> I need a one-to-many to behave like a one-to-one.
>
> The parent instance of my model can only ever have one current child
> instance of another model. Multiple child instances have to exist and be
> kept for the historical record.
>
> The main benefit of one-to-one relationships is that they can be mapped
> together (in the Admin) as an extension of the parent.
>
> In a view I suppose I can use a manager to filter the children into a
> pseudo-one-to-one thingy but how do I do this in the Admin?
>
> Maybe sort them into date order and only show one? Is there a better way?
>
> Thanks for any help
>
> Mike
>
> --
> 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+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en<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.



How many Django web pages does it take . . .

2012-01-06 Thread Bill Beal
Hi all,

I've been doing Django and mostly backend Python for a few months, and
I don't really know the limits of what can be done without resorting
to JavaScript and Ajax. Here's what I need to do: the user wants to
pick an individual from one of a number of lists and have the detailed
information come up editable for the one picked. My top-level list is
[Lions, Tigers, Bears, All]. The user picks Tigers, and then I present
the second-level Tigers list: [Tony, Hobbes, Tigger, Rajah]. The user
picks Hobbes, and then I present the detailed information for Hobbes
in an editable form: name, address etc. How clunky does this have to
be, in terms of mouse clicks and pages downloaded? I've read in more
than one place that if you use JavaScript you'd better have a version
of your page that works OK without it.

For extra credit, what high-powered tools would be needed to do
autocompletion, for example the user starts typing "Hobbes" into the
Name field and as soon as I find a unique match I present the details?
Or, show a list of possible matches when the partial field is not
unique?

I've been reading books, but most of them just show me how to build a
particular kind of website using Django.

Thanks for any help you can lend!

Bill Beal

-- 
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: model for legacy table without primary key

2011-12-30 Thread Bill Beal
But it can't be a primary key if the values are not unique, right?
The four fields are unique together, but not necessarily individually.

Bill Beal


On Fri, Dec 30, 2011 at 12:49 PM, akaariai  wrote:

> You could just define some arbitrary column as primary key. Primary
> key doesn't play any important part in most select queries. It might
> be that some queries would break (like Django trying to group by the
> fake PK column when aggregating), but most things should just work.
> This is what I have done when using some views which do not have
> natural single column primary key. Try and see if this works for your
> usage.
>
>  - Anssi
>
> On Dec 30, 6:50 pm, "Sells, Fred" 
> wrote:
> > I thought I had read somewhere that it was possible to have a model for
> > a legacy table without a primary key as long as the useage was read only
> > and that the method was "filter" and not "get".  I've been searching for
> > quite a while now and all I can find indicates a primary key is
> > mandatory for any model.  I'm using Django 1.3 with MySQL 5.0 but plan
> > to upgrade to MySQL 5.5 if that makes any difference.
> >
> > The table has 4 fields that are unique together: userid, application,
> > role, facility.  I populate the latter 3 by decoding the ldap group.
> > Unfortunately ldap group names are not defined consistently, so I have
> > to write a special parser for each application (that I support in
> > Django).  This table will be refreshed using MySQLdb from a cron job
> > that queries ldap (i.e. no Django at this phase).  This  process updates
> > a generic access table that is used by all my django apps.
> >
> > I control this table, so I could let Django create an autonumber id as
> > primary key, or I could combine all 4 columns to create a  primary key.
> > Since I really don't need or have a good use for a primary key in this
> > table, either technique seems inappropriate.  However if I'm being anal
> > about this whole pk issue and need to just  bite the bullet, so be it.
> >
> > Any sage advice?
> >
> > Fred.
>
> --
> 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: new tables missing from admin page

2011-12-20 Thread Bill Beal
Thanks.  I don't remember doing this when I created the first set of
tables.  Does it happen automatically once?  Or maybe I was mindlessly
working from an example in a book.  I'm a sorcerer's apprentice without a
sorcerer.  (There's a spell-checker pun in there somewhere.)

Bill


On Tue, Dec 20, 2011 at 1:24 PM, Anoop Thomas Mathew wrote:

> Hi,
> You should register the new models in the admin.py.
> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-objects
> Above link should help.
>
> Thanks,
> Anoop Thomas Mathew
> atm
> ___
> Life is short, Live it hard.
>
>
>
>
> On 20 December 2011 23:32, Bill Beal  wrote:
>
>> Hi all,
>>
>> I added some tables to models.py but they didn't show up
>> when I logged in as admin.  I knew already from harsh
>> experience that syncdb will not pick up _changes_ to an
>> existing table, so I deleted the old database before doing
>> syncdb then runserver.  When I didn't find the new tables
>> listed on the admin page, I shut down the server, blew
>> away all .pyc files in the project and app directories, then
>> ran runserver again.  Tables were still missing from admin.
>> sqlall showed the new tables.  dbshell with .tables
>> command showed the new tables.  I'm using Python 2.6.6,
>> Django 1.3, SQLite 3.7.2.  What's the missing link? How
>> can there be any file left that only has the old tables?
>>
>> Bill Beal
>>
>> --
>> 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.



new tables missing from admin page

2011-12-20 Thread Bill Beal
Hi all,

I added some tables to models.py but they didn't show up
when I logged in as admin.  I knew already from harsh
experience that syncdb will not pick up _changes_ to an
existing table, so I deleted the old database before doing
syncdb then runserver.  When I didn't find the new tables
listed on the admin page, I shut down the server, blew
away all .pyc files in the project and app directories, then
ran runserver again.  Tables were still missing from admin.
sqlall showed the new tables.  dbshell with .tables
command showed the new tables.  I'm using Python 2.6.6,
Django 1.3, SQLite 3.7.2.  What's the missing link? How
can there be any file left that only has the old tables?

Bill Beal

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