Re: formset initialization question

2009-03-04 Thread Margie

Yes, I am defining _construct_form() as you do.  I had just not
thought to set initial there - but that makes sense.  For reference,
here is my current code, with it setting initial in _construct_form.
But you may want to read on below before bothering to look at it
because I have a theory about why cleaned_data is not getting set.

class TaskTileDetailCustomBaseFormSetForCreate(BaseFormSet):
def __init__(self, *args, **kwargs):
self.tiles = list(kwargs.pop("tiles"))
self.extra = len(self.tiles)
super(TaskTileDetailCustomBaseFormSetForCreate, self).__init__
(*args, **kwargs)

def _construct_form(self, i, **kwargs):
kwargs["tile"] = self.tiles[i]
kwargs["initial"] = {'tile':self.tiles[i].id}
return super(TaskTileDetailCustomBaseFormSetForCreate,
self)._construct_form(i, **kwargs)

def makeTaskTileDetailFormSetForCreate(tileList, data=None):
TaskTileDetailFormSet = formset_factory(form=TaskTileDetailForm,
formset=TaskTileDetailCustomBaseFormSetForCreate)
taskTileDetailFormSet = TaskTileDetailFormSet(data,
tiles=tileList)
return taskTileDetailFormSet



After debugging into the source some more, I'm finding that my the
problem is related to the fact that empty_permitted is getting set to
True when all of my forms are considered "extra. Specifically, in site-
packages/django/forms/forms.py, in the full_clean() function, I find
that when empty_permitted is set to True, this code executes, which
drops me out of the code without setting cleaned_data at all:

# If the form is permitted to be empty, and none of the form
data has
# changed from the initial data, short circuit any validation.
if self.empty_permitted and not self.has_changed():
return



It seems to me that if I pass in initial when I create the
TaskTileDetailFormSet, ie, like this:

initial = []
for tile in tileList:
initial.append({'tile': tile.id})

taskTileDetailFormSet = TaskTileDetailFormSet(data,
tiles=tileList, initial=initial)

then empty_permitted gets set to False ibecause my initial_form_count
is non-zero.  IE, in site-packages/django/forms/formsets.py, in
_construct_form(), in thh code that looks like this:

# Allow extra forms to be empty.
if i >= self._initial_form_count:
defaults['empty_permitted'] = True

But if I pass initial in via my own _construct_form() function as you
suggested, then I have no initial data, so all of my forms are
"extra".  IN this case self._initial_form_count is 0, and it seems
that the result is that cleaned_data doesn't get set correctly.

I am probably far from undrestanding this, but if what I said is
atually true, it seems like this is actually a bug?  The bug being
that cleaned_data is not getting set correctly when the forms are
created as "extra" forms.  Perhaps cleaned_data is not supposed to get
set in this case?  The whole reason that I happened upon this is
beacuse I am trying to identify which form is which, so I was looking
at cleaned_data['tile'].  I set that myself anyway, so I can just look
at data['tile'].  However, it seems that none of my post data is
getting put in cleaned_data, so that still seems like a general
problem.

Margie






On Mar 3, 11:17 pm, Malcolm Tredinnick 
wrote:
> On Tue, 2009-03-03 at 22:42 -0800, Margie wrote:
> > Hi Malcolm - Sorry, another formset question.  Maybe you'll know the
> > answer offhand, have been trying to figure this out for awhile now.
> > I'm trying to set the initial value for a form field inside the
> > constructor for the form.  The high level goal is to send out the
> > 'tile' field as a hidden input so that I can get it back in the POST
> > so that I can figure out wich 'tile' each form in the forset
> > corresonds to.
>
> > For example, I'm trying to do this in my form constructor
> > (specifically see the ==> line)
>
> > class TaskTileDetailForm(forms.ModelForm):
> >     class Meta:
> >         model=TaskTileDetail
> >         exclude=('task')
>
> If this is a cut-and-paste, this line is almost certainly a bug. The
> "exclude" parameter should be a tuple or a list, so ("task",) or
> ["task"] (note the trailing comma in the tuple case).
>
>
>
> >     def __init__(self, tile, *args, **kwargs):
>
> This line is a probably going to be a problem at some point. You cannot
> just add new positional arguments into the front of the __init__ call
> like this. When Django calls the constructor, it could well be passing
> the "data" parameter as the first argument.
>
> Instead, pass it in as a keyword argument. To wit:
>
>         def __init__(self, *args, **kwargs):
>            tile = kwargs.pop("tile")
>            super(TaskTileDetailForm, self).__init__(*args, **kwargs)
>            ...
>
> That preserves the ordering of positional arguments.
>
> >         super(TaskTileDetailForm, self).__init__(*args, **kwargs)
> >         self.fields['tile'].widget = forms.HiddenInput()
> > ==>     self.fields['til

Re: HttpResponse post

2009-03-04 Thread hoamon

Hi all,

I write a experimental example to reach this requirement.  By AJAX
method, we can make a post type form after server answer.

my example is below here:

http://hoamon.blogspot.com/2009/03/return-httpresponseredirect-by-post.html
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Database connection object in session

2009-03-04 Thread jai_python

Hi. Is it possible to add database connection object in session and
handle in different views.

Thanks in advance.
Jayapal
--~--~-~--~~~---~--~~
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: Cookie problem on multiple sites

2009-03-04 Thread Dids

Fixed the problem :)

Turns out, underscores '_' are not valid characters for domain
names ...

Told you I was new to this...

Thanks all for your input, much appreciated :)

Regards,
Didier,

--~--~-~--~~~---~--~~
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: Database connection object in session

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 03:08 -0800, jai_python wrote:
> Hi. Is it possible to add database connection object in session and
> handle in different views. 

No. Really bad idea. The connection lifecycle is tied to a single
request/response (we close it at the end of the response). Also pickling
database connections, which is how sessions are stored, is not generally
possible.

What is the real problem you are trying to solve? Why doesn't Django's
normal database connection handling work for you?

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: Cookie problem on multiple sites

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 03:14 -0800, Dids wrote:
> Fixed the problem :)
> 
> Turns out, underscores '_' are not valid characters for domain
> names ...
> 
> Told you I was new to this...

Don't feel too bad about missing that. I know it's true, for example,
but I wouldn't have guessed that was going to be the cause of the
problem (and even if I'd seen network traces, I'd guess it would take me
a while to notice the bad domain name). I would suspect it's not
particularly common knowledge, since it just doesn't come up that much.

If that was indeed the issue, then it's a real edge-case. Glad you
solved it in the end, though.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: ManyToOne : cannot form a proper query :(

2009-03-04 Thread [CPR]-AL.exe

Thanks, but i've already read that and there's no answer for my
question. In SQL this would be some query with nested joins.. but i
don't know how to make this query in django..

On 3 мар, 19:17, Alex Gaynor  wrote:
> On Tue, Mar 3, 2009 at 11:13 AM, [CPR]-AL.exe  wrote:
>
> > for example, i have this models:
> > (like here:http://www.djangoproject.com/documentation/models/many_to_one/
> > )
>
> > 
> > from django.db import models
>
> > class Reporter(models.Model):
> >    first_name = models.CharField(max_length=30)
> >    last_name = models.CharField(max_length=30)
> >    email = models.EmailField()
>
> >    def __unicode__(self):
> >        return u"%s %s" % (self.first_name, self.last_name)
>
> > class Article(models.Model):
> >    headline = models.CharField(max_length=100)
> >    pub_date = models.DateField()
> >    reporter = models.ForeignKey(Reporter)
>
> >    def __unicode__(self):
> >        return self.headline
>
> >    class Meta:
> >        ordering = ('headline',)
>
> > 
>
> > I have some amount of articles and i have to reporters, with first
> > names "John" and "Paul".
>
> > I want to get all Articles, created by John and Paul (not only by John
> > and only by Paul). Who this could be done and who could this be done
> > with a Q-object (in one query)?
>
> I suggest you start by taking a look at this section of the 
> docs:http://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-mult...
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Calling a SOAP web service on Django with any kind of a client

2009-03-04 Thread gandra

Hi all!

I am working on web services. The idea is that I have a list of
services on Djnago that can be called by any kind of a client. To
create one web service I used the code from: 
http://www.djangosnippets.org/snippets/979/

The python client which calls the web service is quite simple:

#ws is my Django project dir
from soaplib.client import make_service_client
from ws.views import HelloWorldService
client = make_service_client('http://localhost:8000/hello_world/',
HelloWorldService())
client.say_hello('Dragan', 5)

I get the desired output.

Now, when I call the same web service via: http://www.validwsdl.com/
using public IP I get the following error in the SOAP message:

 Traceback (most recent call last): File "c:\python24\lib\site-packages
\soaplib-0.7.2dev_r27-py2.4.egg\soaplib\wsgi_soap.py", line 226, in
__call__ retval = apply(func, params) File "c:\python24\lib\site-
packages\soaplib-0.7.2dev_r27-py2.4.egg\soaplib\service.py", line 52,
in explainMethod return f(*args, **kwargs) File "C:\DjangoDev\ws\..\ws
\views.py", line 11, in say_hello for i in range(0, times): TypeError:
range() integer end argument expected, got NoneType.

It seems that the parameters Name and number of reps are not supplied
to the say_hello function.

I also tried with testing the web service with http://www.soapui.org/
and it doesn't work. I don't get the return value.

Am I missing something? Can anybody please help me out with this?

Cheers, Dragan.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



opposite of icontains

2009-03-04 Thread koranthala

Hi,
 How do I implement a substring query?
 Please find the example below.
>From Django Documentation:
  Entry.objects.get(headline__icontains='Lennon')
  => This matches the headline 'Today lennon honoured'

My query is the opposite:
   I have the string 'Lennon' inside my DB, and I have to match 'Today
Lennon honoured'
Say:
Entry.objects.get(headline__isubstring='Today Lennon Honoured')
should return headline 'Lennon'.

I checked iregex too, but I cannot seem to solve it myself. If
somebody has solved this, could you please help me out.




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



Appropriate placement for my testcases belonging to a non-app in Django

2009-03-04 Thread madhav

I have built my website in Django. And like any other django project I
have got apps inside the project root directory and some special
folders like(extensions a.k.a custom django command extensions). With
an app, we dont have any problem with having testcases. "tests.py"
inside the app directory will be the solution. But for a special folder
(which is not an app or which doesn't have a models.py) where do I
place the testcases. I tried placing the tests.py inside the
extensions directory and it said the directory is not a model and
unable to run the tests. HOw do I solve this? How can I have a proper
placement of testcases related to non-apps?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ImportError: No module named postgresql_psycopg2.base

2009-03-04 Thread durgaprasad

Hi,
I am new to Django and trying to install and get it running. I
have created a small project and when I execute following

python manage.py runserver

I get this error -

ImportError: No module named postgresql_psycopg2.base


Here are the details -

/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-packages/
django/db/backends
Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
packages/django/core/management/__init__.py", line 340, in
execute_manager
utility.execute()
  File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
packages/django/core/management/__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
packages/django/core/management/base.py", line 192, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
packages/django/core/management/base.py", line 219, in execute
output = self.handle(*args, **options)
  File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
packages/django/core/management/base.py", line 348, in handle
return self.handle_noargs(**options)
  File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
packages/django/core/management/commands/shell.py", line 17, in
handle_noargs
from django.db.models.loading import get_models
  File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
packages/django/db/__init__.py", line 24, in 
backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {},
[''])
ImportError: No module named postgresql_psycopg2.base


Although I have successfully installed both django and psycopg2, I am
getting the above error. I have also set the PYTHONPATH correctly.
Is there anything else that I am missing?

--~--~-~--~~~---~--~~
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 to Django and a few basic questions

2009-03-04 Thread ch...@secondfoundation.net

Hi group,

as the subject says, I'm new to Django. I worked through some
tuturials and djangobook.com for the 1.0.2 version as far as there
already is documentation. Anyway, I'm still not certain Django is the
right answer to my needs.

What I want to do:

I need to write a web based admin frontend to a OSS based mail gateway
that consist the usual suspects (Postfix, SA, antivir, some custom
scripts, you name it). There are already some frontends to some of
those tools but there's always some functionality or tools missing.

I need to be able to configure ALL those apps in a consistent front
end (including the customers corporate design/identity) which
basically means editing config textfiles (but hiding them from the
user), (re)starting services, start scripts, show status of services,
check input for sanity, you get it.

What I have:

Knowledge of  the underlaying OSS apps as mentioned above.
Thirst for knowledge.
I like Python.

What I don't have:

My programming background is, well, outdated (assembler and turbo
pascal back in the 80s).
SQL skill is very limited.
HTML/CSS/webstuff knowledge not existent.
Time is somewhat limited.

My first question is, is Django the right tool to accomplish my task?
I'm a bit uncertain. If yes, are there any Django apps I could use for
template/guideline that already do what I need? If Django is not what
I need, are there any recommendations considering my state of
knowledge?

Thanks!

Chris

--~--~-~--~~~---~--~~
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: Cookie problem on multiple sites

2009-03-04 Thread Ramiro Morales

On Wed, Mar 4, 2009 at 9:14 AM, Dids  wrote:
>
> Fixed the problem :)
>
> Turns out, underscores '_' are not valid characters for domain
> names ...
>
> Told you I was new to this...
>
> Thanks all for your input, much appreciated :)
>

Oops, when I saw your email, I searched in my GMail inbox for "cookie
admin ie" and one of the ten or so threads it found was this one from
django-users:

http://groups.google.com/group/django-users/browse_frm/thread/17d26d2b19b092d4

where the same conclusion was arrived at.

So that would be another tip: search in the relevant mailing lists
archives with sensible terms. With pieces of code like IE probabilities
are high somebody has already suffered the same problems.

-- 
 Ramiro Morales

--~--~-~--~~~---~--~~
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: Aggregating Ignores Slicing?

2009-03-04 Thread Waylan Limberg

On Mar 3, 8:55 am, Ross  wrote:
> I have started using aggregation, but it seems to ignore any slicing I
> do on a QuerySet before calling aggregate. This is what I'm doing:
>
> Product.objects.order_by("-price")[:100].values("price").aggregate(Max
> ("price"), Min("price"))
>
> I want the maximum and minimum price for the products with the top 100
> largest prices. The aggregate function, however, returns the maximum
> and minimum price for all Products--it ignores the [:100] slice.
>

You do realize that because your ordering by "price" your min and max
will be the first and last items in the returned QuerySet, don't you?
So something like:

>>> qs = Product.objects.order_by("-price")[:100]
>>> max = qs.values("price")[0]
>>> min = qs.values("price")[-1]

The above is untested, but you should get the idea. Yeah, it would
seem that aggregation would be nice for this, but if this works...
--~--~-~--~~~---~--~~
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 will not match r^sip/conf string in urls.py on Apache2 / modpython

2009-03-04 Thread Dan

Url pattern below r^sip/conf and sip/createfile work for development
server but Apache comes up with a 404 error. Note that the error is
shown as Apache error not Django parsing error. So, is it Apache not
using the Python interpreter or something with Django? Note that
changing the name to station/conf and station/createfile works.
urlpatterns = patterns('',
# Example:
# (r'^sipprovision/', include('sipprovision.foo.urls')),

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

# Uncomment the next line to enable the admin:
(r'^admin/(.*)', admin.site.root),
(r'^ext/(?P\d+)/$',ExtensionDetail),
(r'^ext/add/$',ExtensionAdd),
(r'^ext/add/(?P\w+)',ExtAddToContext),
(r'^ext/scripts/all$',allscripts),
(r'^ext/scripts/(?P\w+)',extscripts),
(r'^sip/conf$',sipconf),
(r'^station/add/$',station_add ),
(r'^sip/createfile/$',create_sip_file),
(r'^sys/(?P\d+)/$',SysDetail),
)


--~--~-~--~~~---~--~~
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: ImportError: No module named postgresql_psycopg2.base

2009-03-04 Thread Rajesh D

> I am new to Django and trying to install and get it running. I
> have created a small project and when I execute following
>
> python manage.py runserver
>
> I get this error -
>
> ImportError:Nomodulenamedpostgresql_psycopg2.base


>
> Here are the details -
>
> /net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-packages/
> django/db/backends
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
> execute_manager(settings)
>   File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
> packages/django/core/management/__init__.py", line 340, in
> execute_manager
> utility.execute()
>   File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
> packages/django/core/management/__init__.py", line 295, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
> packages/django/core/management/base.py", line 192, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
> packages/django/core/management/base.py", line 219, in execute
> output = self.handle(*args, **options)
>   File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
> packages/django/core/management/base.py", line 348, in handle
> return self.handle_noargs(**options)
>   File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
> packages/django/core/management/commands/shell.py", line 17, in
> handle_noargs
> from django.db.models.loading import get_models
>   File "/net/storm4/dpawar/3rdparty/python2.5.4/lib/python2.5/site-
> packages/django/db/__init__.py", line 24, in 
> backend = __import__('%s.base' % settings.DATABASE_ENGINE, {}, {},
> [''])
> ImportError:Nomodulenamedpostgresql_psycopg2.base
>
> Although I have successfully installed both django and psycopg2, I am
> getting the above error. I have also set the PYTHONPATH correctly.
> Is there anything else that I am missing?

It's very likely that your Django installation is corrupt. Did you
install it from your operating system's packaging tool or directly
from source? I would suggest completely wiping out the django
directory from here: /net/storm4/dpawar/3rdparty/python2.5.4/lib/
python2.5/site-packages/

Then, download and install Django from http://djangoproject.com.

-Rajesh D
--~--~-~--~~~---~--~~
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 Flatpages nd set_language

2009-03-04 Thread tdelam

Hi everyone,

I am building a bilingual cms type web site using Flatpages and django
admin to obviously input the content. I am using django-multilingual.
I need to be able to swap languages from one to another remembering
the page the user is on, I am aware of set_language and I created a
testcase to get that working - works fine but using a dropdown menu.
It  seems set_language accepts a POST only. How can I get it to accept
a GET so I can use links for changing languages instead of a dropdown
menu?

Trevor
--~--~-~--~~~---~--~~
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 will not match r^sip/conf string in urls.py on Apache2 / modpython

2009-03-04 Thread Rajesh D



On Mar 4, 9:58 am, Dan  wrote:
> Url pattern below r^sip/conf and sip/createfile work for development
> server but Apache comes up with a 404 error. Note that the error is
> shown as Apache error not Django parsing error. So, is it Apache not
> using the Python interpreter or something with Django?

Looks like it. Perhaps you should paste the relevant bits from your
Apache config? May be there's a virtual host file that hooks on to
the /sip/ location? It's easy to miss that part of the config if it's
in one of your "sites-enabled" sub-directories instead of in the main
apache conf.

-RD

--~--~-~--~~~---~--~~
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 will not match r^sip/conf string in urls.py on Apache2 / modpython

2009-03-04 Thread Rajesh Dhawan



Rajesh D wrote:
> On Mar 4, 9:58 am, Dan  wrote:
> > Url pattern below r^sip/conf and sip/createfile work for development
> > server but Apache comes up with a 404 error. Note that the error is
> > shown as Apache error not Django parsing error. So, is it Apache not
> > using the Python interpreter or something with Django?
>
> Looks like it. Perhaps you should paste the relevant bits from your
> Apache config? May be there's a virtual host file that hooks on to
> the /sip/ location? It's easy to miss that part of the config if it's
> in one of your "sites-enabled" sub-directories instead of in the main
> apache conf.

You could also completely disconnect your Django config from Apache
and see what Apache does with the /sip/* URLs then.
--~--~-~--~~~---~--~~
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 Flatpages nd set_language

2009-03-04 Thread Rajesh D

Hi Trevor,

> I am building a bilingual cms type web site using Flatpages and django
> admin to obviously input the content. I am using django-multilingual.
> I need to be able to swap languages from one to another remembering
> the page the user is on, I am aware of set_language and I created a
> testcase to get that working - works fine but using a dropdown menu.
> It  seems set_language accepts a POST only. How can I get it to accept
> a GET so I can use links for changing languages instead of a dropdown
> menu?

You can't. That built-in view only accepts a POST for a good reason:
Since that view changes the internal state of the application, a web
app that wants to be a good citizen is recommended not to use GET.
See: http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

With that caveat, if you still want to use a GET, just copy Django's
built-in view into your own custom view and modify it for your own
needs:
http://code.djangoproject.com/browser/django/trunk/django/views/i18n.py

-RD

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



what would be a good schema for a facebook mini feed like app ?

2009-03-04 Thread uno...@gmail.com

I have community features in my app - commenting, favoriting,friending
etc.

I'm wondering what would be a good schema for a facebook like mini
feed app ? Where each user's acitivity stream is showed on their
profile page.


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



Problems with satchmo

2009-03-04 Thread Oumayrita

I'm New in satchmo
I install this store, i tried to see the store by URL:" 
http://127.0.0.1:8000/shop";
and And i click to display the detail's product, i found this error
"Caught an exception while rendering: maximum recursion depth
exceeded"
I make search but i didn't find a cause for this error.
Please help me.. :)

--~--~-~--~~~---~--~~
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: delete items in queryset results?

2009-03-04 Thread adrian


I ended up doing the following:

1. raw SQL to get the IDs of the rows I want.   This required an SQL
statement with an inner JOIN subquery specifically:

SELECT f.id, f.species_name, f.date from (select species_name, max
(date) as maxdate from lister_importedsighting GROUP BY species_name)
as x inner join lister_importedsighting as f on f.species_name =
x.species_name and f.date = x.maxdate

2. Then used the result of that to filter a QuerySet using:

  results = my_custom_sql(sql)
  id_list = []
  for row in results:
id_list.append(row[0])
  query_set = query_set.filter(id__in=id_list)

--~--~-~--~~~---~--~~
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: Problems with satchmo

2009-03-04 Thread Chris Moffitt
You've posted this to the django users group. You'll get more support from
the satchmo-users group.

When you post there, please include a dpaste link with your traceback.

Also, please include which version of Satchmo you're using and the steps
required to reproduce the error.

-Chris

On Wed, Mar 4, 2009 at 9:17 AM, Oumayrita wrote:

>
> I'm New in satchmo
> I install this store, i tried to see the store by URL:"
> http://127.0.0.1:8000/shop";
> and And i click to display the detail's product, i found this error
> "Caught an exception while rendering: maximum recursion depth
> exceeded"
> I make search but i didn't find a cause for this error.
> Please help me.. :)
>
> >
>

--~--~-~--~~~---~--~~
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 will not match r^sip/conf string in urls.py on Apache2 / modpython

2009-03-04 Thread Dan

Looks like I had a sip directory under my templates so was confusing
Apache I guess. Anyway, fixed now so thanks. Renamed it as noted
above.

On Mar 4, 9:10 am, Rajesh Dhawan  wrote:
> Rajesh D wrote:
> > On Mar 4, 9:58 am, Dan  wrote:
> > > Url pattern below r^sip/conf and sip/createfile work for development
> > > server but Apache comes up with a 404 error. Note that the error is
> > > shown as Apache error not Django parsing error. So, is it Apache not
> > > using the Python interpreter or something with Django?
>
> > Looks like it. Perhaps you should paste the relevant bits from your
> > Apache config? May be there's a virtual host file that hooks on to
> > the /sip/ location? It's easy to miss that part of the config if it's
> > in one of your "sites-enabled" sub-directories instead of in the main
> > apache conf.
>
> You could also completely disconnect your Django config from Apache
> and see what Apache does with the /sip/* URLs then.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



CMS on Google Appengine

2009-03-04 Thread poematrix

Is it possible to utilize the Django CMS on Google Appengine? As you
know, Google Appengine by default provides support for the Django
template system. I am wondering if it is possible to use the CMS as
well. Pointers to how-to's regarding this would be much appreciated.
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: Aggregating Ignores Slicing?

2009-03-04 Thread Alex Gaynor
On Wed, Mar 4, 2009 at 9:24 AM, Waylan Limberg  wrote:

>
> On Mar 3, 8:55 am, Ross  wrote:
> > I have started using aggregation, but it seems to ignore any slicing I
> > do on a QuerySet before calling aggregate. This is what I'm doing:
> >
> > Product.objects.order_by("-price")[:100].values("price").aggregate(Max
> > ("price"), Min("price"))
> >
> > I want the maximum and minimum price for the products with the top 100
> > largest prices. The aggregate function, however, returns the maximum
> > and minimum price for all Products--it ignores the [:100] slice.
> >
>
> You do realize that because your ordering by "price" your min and max
> will be the first and last items in the returned QuerySet, don't you?
> So something like:
>
> >>> qs = Product.objects.order_by("-price")[:100]
> >>> max = qs.values("price")[0]
> >>> min = qs.values("price")[-1]
>
> The above is untested, but you should get the idea. Yeah, it would
> seem that aggregation would be nice for this, but if this works...
>  >
>

But that requires actually pulling in all the records, not a big deal when
it's 100, but if it's more, and network latency is an issue you don't want
to do that.  Plus I don't think negative slicing works in SQL.

Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: what would be a good schema for a facebook mini feed like app ?

2009-03-04 Thread Rajesh D



On Mar 4, 10:25 am, "uno...@gmail.com"  wrote:
> I have community features in my app - commenting, favoriting,friending
> etc.
>
> I'm wondering what would be a good schema for a facebook like mini
> feed app ? Where each user's acitivity stream is showed on their
> profile page.

Google for Django tumblelog or Django jellyroll. Here's a good
starting point:

http://ryanberg.net/blog/2008/jun/24/basics-creating-tumblelog-django/

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



Best practices: generating large dynamic files

2009-03-04 Thread Jeff Gentry

In my project I have a need to generate CSV output files for
download.  Some of these files aren't overly large - 1-20MB or so, but
they can get quite big (currently the largest are several hundred MB and
this could grow with time).

This would appear to be a case where there's no magic bullet, but I was
looking to see what folks thought the best way to handle this.  When I
first put this together a while back I knew very little of both python and
django and came up wtih what now seems to be a naive solution - in memory
I pulled the appropriate data, constructed a list of lists in memory (w/
for loops & list comprehensions, no generators involved), built a
HttpResponse object w/ the appropriate headers and then attached the
output of csv.writer() to it, and returned this mess.

As you might imagine this was both slow and a complete memory hog, and I'm
looking for better ways to do this.  If nothing else, it seems like making
use of generators should trade some of the speed for a heck of a lot of
memory and would probably be an overall better solution than storing
a list of hundreds of thousands of lists in memory.

One thought was to write out the file to a staging area, making use of
generators to ease that and then return a redirect to that file.

Another thought was that perhaps there's a better way to do it w/o
involving the middle man of an actual file on disk, but if so that's
beyond my current level of knowledge. 

Any ideas?

Thanks
-J


--~--~-~--~~~---~--~~
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: what would be a good schema for a facebook mini feed like app ?

2009-03-04 Thread uno...@gmail.com

nice..

thanks, that answers my question.

On Mar 4, 11:09 am, Rajesh D  wrote:
> On Mar 4, 10:25 am, "uno...@gmail.com"  wrote:
>
> > I have community features in my app - commenting, favoriting,friending
> > etc.
>
> > I'm wondering what would be a good schema for a facebook like mini
> > feed app ? Where each user's acitivity stream is showed on their
> > profile page.
>
> Google for Django tumblelog or Django jellyroll. Here's a good
> starting point:
>
> http://ryanberg.net/blog/2008/jun/24/basics-creating-tumblelog-django/
>
> -RD
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



getting started...with django

2009-03-04 Thread mseg...@gmail.com

hi  there !  am new in django and i  need help on getting started...
if you are the guy please email me

--~--~-~--~~~---~--~~
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: getting started...with django

2009-03-04 Thread CLIFFORD ILKAY
mseg...@gmail.com wrote:
> hi  there !  am new in django and i  need help on getting started...
> if you are the guy please email me

Welcome! Start here:
. Don't worry if
it doesn't all make sense at first. Just follow the steps exactly and by
the end of the tutorial, the pieces will fall into place.
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326


smime.p7s
Description: S/MIME Cryptographic Signature


Re: getting started...with django

2009-03-04 Thread Paul Nema
After the tutorial and reading the docs, if you're the visual type, try
these screencasts.  Very helpful and illuminating.

http://thisweekindjango.com/screencasts/?page=3
and
http://showmedo.com/videos/django


On Wed, Mar 4, 2009 at 11:58 AM, CLIFFORD ILKAY
wrote:

> mseg...@gmail.com wrote:
> > hi  there !  am new in django and i  need help on getting started...
> > if you are the guy please email me
>
> Welcome! Start here:
> . Don't worry if
> it doesn't all make sense at first. Just follow the steps exactly and by
> the end of the tutorial, the pieces will fall into place.
> --
> Regards,
>
> Clifford Ilkay
> Dinamis
> 1419-3266 Yonge St.
> Toronto, ON
> Canada  M4N 3P6
>
> 
> +1 416-410-3326
>

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



translating app name ... again

2009-03-04 Thread patrickk

so far, it doesn´t seem possible to translate the app-names within the
admin-interface, which results in a strange index-site with mixed
languages.

any updates on this issue? any ideas?

thanks,
patrick


--~--~-~--~~~---~--~~
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 class at the Big Nerd Ranch

2009-03-04 Thread juampa

I am pleased to announce that the Big Nerd Ranch is offering the
intensive, five-day Django Bootcamp. If you are interested in learning
Django development quickly, this is the place to go. The class is
confirmed for April 13-17 2009 in Atlanta, and there are still seats
available.

Please visit www.bignerdranch.com for more information, including a
class syllabus.

Thanks,

Juan Pablo Claude
Instructor
Big Nerd Ranch, Inc.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Is a Complex filter with __in and __exact possible?

2009-03-04 Thread Alfonso

I've set up a simple filter to grab a queryset of objects matching a
list of (many to many) categories like this:

Book.objects.filter(categories__in=[1,2,3]).order_by('name').distinct
()

It's good, it works... it returns any books in those three
categories.But I'd like to return ONLY Books with those three
categories?

I thought something like categories__exact__in would work but clearly
not.

Any ideas?

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: URL quoting and escaping

2009-03-04 Thread Rob Hudson

I decided to follow Google's lead and pass it as a parameter of the
query string instead and all is well now.

Thanks for the feedback... I never considered it might be the web
server.

-Rob

--~--~-~--~~~---~--~~
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: extending admin change_form template

2009-03-04 Thread AmanKow

On Mar 3, 10:50 am, Jon Reck  wrote:
> I'm a novice Python and Django programmer so please don't assume a lot of
> knowledge here.
> I'm trying to place a link on an admin change form to a label printing
> function. I'd like to pass the id of the current record to the function. If
> I hardwire it in (see below- record number = 920) it works. I can't figure
> out how to code this so the current record number is inserted by the
> program. Is there some sort of template variable that I can use for this? Or
> can you suggest a better approach?
>
> thanks , Jon
>
> {% extends "admin/change_form.html" %}
> {% load i18n %}
> {% block after_field_sets %}
> Print Labels
> {% endblock %}

I believe that the object id for the current object is passed in the
context in object_id.

You can see it in use in the history link rendering in admin/
change_form.html:
href="../../../r/{{ content_type_id }}/{{ object_id }}/"

Wayne

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



Accessing the development server from another machine.

2009-03-04 Thread Joe Goldthwaite

I've been developing with the development server with the default settings
without problems. My main development is done in a Windows virtual machine
running on a Macbook Pro. Today I wanted to test the output with Safari.
Since I don't have that installed in Windows, I decided to just try
connecting with Safari from OSX to the virtual machine.  That led me to an
adventure into the runserver settings.

It looks like I should be able to just enter "manage.py runserver
192.168.1.117:8000" to expose the development server to the network.  When I
try it, it looks like it's working and I get this;

>c:\DjangoProjects\FiscalCalendar>manage.py runserver 192.168.1.117:8000
>Validating models...
>0 errors found
>
>Django version 1.0.2 final, using settings 'FiscalCalendar.settings'
>Development server is running at http://192.168.1.117:8000/
>Quit the server with CTRL-BREAK.

It looks like it's working but when I enter the address in the browser I get
a connection timeout error. The server never gets the request. I'm not
running any firewall. Is there some other setting somewhere that allows the
development server to serve up requests to external browsers?


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



simple model problem

2009-03-04 Thread arbi

Hello,
I am new to Django and programming...
I have a model similar to this one :

class myModel :
  attribute 1 = models.ForeignKey(myModel2, primary_key = True)
  attribute 2 = models.ForeignKey(myModel3, primary_key = True)

is it possible to have two primary keys?
In fact I want that the id of an instance of this class is the
concatenation of the (attribute 1 +attribute2).
How to do this?
thx

Arbi
--~--~-~--~~~---~--~~
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: Accessing the development server from another machine.

2009-03-04 Thread Alex Gaynor

On 3/4/09, Joe Goldthwaite  wrote:
>
> I've been developing with the development server with the default settings
> without problems. My main development is done in a Windows virtual machine
> running on a Macbook Pro. Today I wanted to test the output with Safari.
> Since I don't have that installed in Windows, I decided to just try
> connecting with Safari from OSX to the virtual machine.  That led me to an
> adventure into the runserver settings.
>
> It looks like I should be able to just enter "manage.py runserver
> 192.168.1.117:8000" to expose the development server to the network.  When I
> try it, it looks like it's working and I get this;
>
>>c:\DjangoProjects\FiscalCalendar>manage.py runserver 192.168.1.117:8000
>>Validating models...
>>0 errors found
>>
>>Django version 1.0.2 final, using settings 'FiscalCalendar.settings'
>>Development server is running at http://192.168.1.117:8000/
>>Quit the server with CTRL-BREAK.
>
> It looks like it's working but when I enter the address in the browser I get
> a connection timeout error. The server never gets the request. I'm not
> running any firewall. Is there some other setting somewhere that allows the
> development server to serve up requests to external browsers?
>
>
> >
>

Try running the server at 0:8000 this tells it to serve requests to all hosts.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Accessing the development server from another machine.

2009-03-04 Thread CLIFFORD ILKAY
Joe Goldthwaite wrote:
> My main development is done in a Windows virtual machine
> running on a Macbook Pro. Today I wanted to test the output with Safari.
[snip]
> It looks like it's working but when I enter the address in the browser I get
> a connection timeout error. The server never gets the request. I'm not
> running any firewall.

This is quite likely a problem with the network between your virtual
machine and the physical machine. With virtualization, you have multiple
ways of setting up the network between the VM and the hardware host and
not setting up a network is even an option with some virtualization
schemes so you must ensure that OS X and the Windows VM can see one
another on the network first.
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326


smime.p7s
Description: S/MIME Cryptographic Signature


DB Queries of unusual size

2009-03-04 Thread Kottiyath

I am now managing a web server for medium (going on high) traffic
site. I see that currently for each POST, it takes ~55-60 separate DB
queries for providing a reply.
Is this unusual? The total time taken for the queries is less than a
second.
I looked at the design and it looks somewhat well designed - i.e. to
decrease the queries, we will have to do quite a bit of nasty things.
Can someone give me an idea whether this amount of queries is usual?
--~--~-~--~~~---~--~~
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: DB Queries of unusual size

2009-03-04 Thread Alex Gaynor



On Mar 4, 2009, at 1:44 PM, Kottiyath  wrote:

>
> I am now managing a web server for medium (going on high) traffic
> site. I see that currently for each POST, it takes ~55-60 separate DB
> queries for providing a reply.
> Is this unusual? The total time taken for the queries is less than a
> second.
> I looked at the design and it looks somewhat well designed - i.e. to
> decrease the queries, we will have to do quite a bit of nasty things.
> Can someone give me an idea whether this amount of queries is usual?
> >

One generally tries to avoid too many queries, and 50+ would usually  
five me pause however the question is always is it fast enough. And if  
it is there is mo reason to worry. If it isn't you get to sit down and  
do some profiling.

Alex

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



An easy way to work with webservices and create template tags.

2009-03-04 Thread tristan

I'm a designer learning python and Django by example, and its a
brilliant system.
On my project I have a set of our own XML webservices to call using a
variety of methods. The aim is to then get access to the data returned
and expose the individual elements in the XML as Django template tags
that I can then manipulate in my web application.
I have looked at the amazon web service example, but its a little over
my head. I wondered if anyone had any libraries that I might be able
to adapt to do this without having to write too much python?


--~--~-~--~~~---~--~~
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: DB Queries of unusual size

2009-03-04 Thread Rajesh D



On Mar 4, 1:44 pm, Kottiyath  wrote:
> I am now managing a web server for medium (going on high) traffic
> site. I see that currently for each POST, it takes ~55-60 separate DB
> queries for providing a reply.
> Is this unusual? The total time taken for the queries is less than a
> second.
> I looked at the design and it looks somewhat well designed - i.e. to
> decrease the queries, we will have to do quite a bit of nasty things.
> Can someone give me an idea whether this amount of queries is usual?

The answer is "it depends". Generally speaking, that number of queries
would be considered high and should at least cause a developer to take
a second look at that piece more carefully as it might be an
indication of an architectural/design deficiency.

If you can share some samples of what these queries are doing, what
Django code causes them to execute, and what that view is actually
supposed to do, may be people can suggest options.

For example, does that view issue a lot reads from the DB for data
that doesn't change often? If so, you could consider memcaching that
data. Similarly, some of those read queries could benefit from adding
relevant models to its "select_related()" call.

-RD


--~--~-~--~~~---~--~~
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: DB Queries of unusual size

2009-03-04 Thread Kottiyath



On Mar 5, 12:05 am, Rajesh D  wrote:
> On Mar 4, 1:44 pm, Kottiyath  wrote:
>
> > I am now managing a web server for medium (going on high) traffic
> > site. I see that currently for each POST, it takes ~55-60 separate DB
> > queries for providing a reply.
> > Is this unusual? The total time taken for the queries is less than a
> > second.
> > I looked at the design and it looks somewhat well designed - i.e. to
> > decrease the queries, we will have to do quite a bit of nasty things.
> > Can someone give me an idea whether this amount of queries is usual?
>
> The answer is "it depends". Generally speaking, that number of queries
> would be considered high and should at least cause a developer to take
> a second look at that piece more carefully as it might be an
> indication of an architectural/design deficiency.
>
> If you can share some samples of what these queries are doing, what
> Django code causes them to execute, and what that view is actually
> supposed to do, may be people can suggest options.
>
> For example, does that view issue a lot reads from the DB for data
> that doesn't change often? If so, you could consider memcaching that
> data. Similarly, some of those read queries could benefit from adding
> relevant models to its "select_related()" call.
>
> -RD

Thank you very much for the replies.
Since I will have to get permission before sharing the query
information I will just provide an overview.
There are ~20 main tables and a lot of enumerated domains. Most of the
db queries are occuring for getting the values from the enumerated
domains.
That is why I mentioned that it is not taking too much time (~1 second
per query - is that also high? ) because the values of enumerated
domain are cached by DB.
There are not too many joins - every query will have overall 6-7 inner
joins max.
Now that you guys are suggesting that the queries are very high, I
will try out the following options
(a) memcaching (b) remove enumerated domains (c) select_related with
limit 3
Are there any other suggestions? Thank you again for the quick
replies.


--~--~-~--~~~---~--~~
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: formset of ModelForms missing functionality?

2009-03-04 Thread Margie

Hi Malcolm.  So after reviewing your pointers, I had high hopes of
being able to move to using the modelformset_factory, but I still seem
to have problems.  The problem I run into is that when _construct_form
(the one in django/forms/models.py) is called, it tries to do this:

if i < self._initial_form_count:
kwargs['instance'] = self.get_queryset()[i]

I have no objects of my model yet and get_queryset()  returns
self._queryset, which is [].  The above [i] index then causes a 'list
index out of range exception'.  I think this was what I first
encountered which made me think that I had to have a queryset to use
modelformset_factory.

I cleaned up other things that you mentioned in your other posts  -
thanks much for those pointers.  I've put my current code at

http://dpaste.com/6281/

Note that when I instantiate the formset:

taskTileDetailFormSet = TaskTileDetailFormSet(data=data,
  tiles=tileList,
  initial=
[{"tile":tile.id} for tile in tileList]

I am creating an initial entry for each form that I want created.
Inside __init__ for TaskDetailCustomBaseFormSetForCreate I thus set
self.extra to 0.  My understanding is that I don't need any "extras"
in this case because I am using initial to specify all of the forms
that I want.  (Setting extra to a larger number had no effect on the
list index error - am just mentioning this for clarity)

Anyway, I must be doing something dumb... sigh.  The
modelformset_factory works fine for me in another case query I have an
existing set of model instances - just can't get it to work in this
case where I don't yet have the model instances.

Thanks for any pointers.

Margie






On Mar 3, 10:54 pm, Margie  wrote:
> Yeah, I need to go back and review.  I think my original problem was
> that I just didn't think about using extra to define the intial forms
> - I was thinking I needed a queryset.   Your first resonse addressed
> that. But then you mentioned something about exclude and that made me
> think that maybe I couldn't use it.  Of course I can.
>
> Anyway, I need to see if I can get myself back to a steady working
> state and then am going to revisit using the modelformset_factory.
> Thanks for the pointers.
>
> Margie
>
> On Mar 3, 10:24 pm, Malcolm Tredinnick 
> wrote:
>
> > On Wed, 2009-03-04 at 16:49 +1100, Malcolm Tredinnick wrote:
> > > On Tue, 2009-03-03 at 21:44 -0800,Margiewrote:
>
> > > > My model does have multiple fields in it - the Book thing was just an
> > > > example to simplify.  And I do have fields that I need to exclude.  Am
> > > > I not able to exclude fields with the modelformset_factory?  
>
> > > The example code I have showed fields being excluded.
>
> > Gargh. Important typo: that should have said "the example code I have
> > *posted*", in my previous post.
>
> > Also, the documentation for model forms shows, similarly, how to exclude
> > fields ([1]). So I don't understand your question.
>
> > [1]http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#control...
>
> > Regards,
> > Malcolm
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Can't run django on Apache

2009-03-04 Thread John Maines

Hello:

I've installed Django 1.0 on Ubuntu and am trying to get it to run on
Apache. Apache is installed, working fine, with mod-python also in
place. I'm new at everything Linux.

But when I try to run my app (a test blog), Apache gives an
ImportError message (below) I have come across NUMEROUS references to
this error message, and the solution usually seems to involve changing
the Python Path. But nothing I try seems to work. I've tried using /
user/local for a path, /var/www; the path to my app. Nothing works.
Any suggestions?

MOD_PYTHON ERROR

ProcessId:  9980
Interpreter:'mysite'

ServerName: 'ubuntu.ubuntu-domain'
DocumentRoot:   '/var/www/'

URI:'/mysite'
Location:   '/'
Directory:  None
Filename:   '/var/www/mysite'
PathInfo:   ''

Phase:  'PythonHandler'
Handler:'django.core.handlers.modpython'

Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1229, in _process_target
result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1128, in _execute_target
result = object(arg)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 228, in handler
return ModPythonHandler()(req)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 191, in __call__
self.load_middleware()

  File "/usr/lib/python2.5/site-packages/django/core/handlers/
base.py", line 31, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:

  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py",
line 28, in __getattr__
self._import_settings()

  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py",
line 59, in _import_settings
self._target = Settings(settings_module)

  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py",
line 94, in __init__
raise ImportError, "Could not import settings '%s' (Is it on
sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE,
e)

ImportError: Could not import settings 'settings' (Is it on sys.path?
Does it have syntax errors?): No module named settings


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



Three Physical Tiers

2009-03-04 Thread ruffeo

Does anyone know how to develop a complex django project in a 3 tiered
network environment, still using the MCV architecture?

I.E. Web Server (view and control code), App Server (model code), and
Database Server




--~--~-~--~~~---~--~~
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: file validation in admin form

2009-03-04 Thread Ty

Perhaps instead of rejecting specific file types, you should only
allow specific file types? Most of the time a file upload is taking
place the programmer has some sort of idea what the user will upload.
This is probably the most secure method, even though it won't work for
everyone.

On Feb 20, 6:57 pm, Michael Repucci  wrote:
> Thanks for the pointer! The docs are 
> athttp://docs.djangoproject.com/en/dev/ref/forms/validation/#ref-forms-
> I had been letting Django use the default forms, and hadn't read much
> about forms, so I'd missed that hook. I used a clean_()
> method and it works perfectly. The only thing left is deciding which
> files are dangerous, so if anyone has any tips on that topic please
> let me know. I'm really only a novice when it comes to web
> programming, so I'm not familiar with the different security threats
> that are out there. Thanks again!
>
> On Feb 20, 6:25 pm, Briel  wrote:
>
> > Validation is a big subject, and the validation of files can be very
> > complex aswell. Anyways to validate you need to define a clean method
> > in your form. Here you put the code that can test things like file
> > types, and whatever you can think of using python. I can't get you the
> > link as I'm not at my laptop, but if you search the django docs for
> > "form validation" "clean" or "cleaned_data" you should be able to find
> > the right doc. You want to read about the clean method an is_valid().
>
> > On 20 Feb., 22:09, Michael Repucci  wrote:
>
> > > I'm totally new to Django and authorized/secure web apps, and really
> > > loving it for this. But I've got a few really novice questions. I've
> > > got a model with a FileField, to which users can upload an arbitrary
> > > file. In the model docs for the FileField it says, "Validate all
> > > uploaded files." And I'm not sure where to do this or how. Is this
> > > through the save_model method of the ModelAdmin class? If so, what is
> > > the basic format, because not executing obj.save() didn't seem to do
> > > the trick.
>
> > > Also, as mentioned in the docs, I don't want to allow a user to upload
> > > a PHP script or similar, and execute it by visiting the link, but I
> > > would like users to be able to place any of various file types on the
> > > server so that other users can download them. Is it enough to just
> > > exclude files with certain extensions (e.g., PHP, CGI, etc.), and if
> > > so, is there a list of all the "dangerous" file extensions somewhere?
>
> > > Thanks for your help in advance!
--~--~-~--~~~---~--~~
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: Q search with foreign key

2009-03-04 Thread Jesse

Thanks!  That worked.
--~--~-~--~~~---~--~~
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: Can't run django on Apache

2009-03-04 Thread xankya

I guess u need to set python path to mysite plus django folders

In httpd.conf:


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonDebug On
PythonPath "['path to mysite', 'path to django'] + sys.path"


--~--~-~--~~~---~--~~
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: Can't run django on Apache

2009-03-04 Thread Maines, John


Thanks. That's one of the about 50 variables I have tried with the path 
settings ... still no luck.

-- John

-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com]on Behalf Of xankya
Sent: Wednesday, March 04, 2009 4:28 PM
To: Django users
Subject: Re: Can't run django on Apache



I guess u need to set python path to mysite plus django folders

In httpd.conf:


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonDebug On
PythonPath "['path to mysite', 'path to django'] + sys.path"




--~--~-~--~~~---~--~~
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: Can't run django on Apache

2009-03-04 Thread Danny Brown

try above but change /mysite to /mysite/ and settings to mysite/settings

On Wed, Mar 4, 2009 at 3:31 PM, Maines, John  wrote:
>
>
> Thanks. That's one of the about 50 variables I have tried with the path 
> settings ... still no luck.
>
> -- John
>
> -Original Message-
> From: django-users@googlegroups.com
> [mailto:django-us...@googlegroups.com]on Behalf Of xankya
> Sent: Wednesday, March 04, 2009 4:28 PM
> To: Django users
> Subject: Re: Can't run django on Apache
>
>
>
> I guess u need to set python path to mysite plus django folders
>
> In httpd.conf:
>
> 
>    SetHandler python-program
>    PythonHandler django.core.handlers.modpython
>    SetEnv DJANGO_SETTINGS_MODULE settings
>    PythonDebug On
>    PythonPath "['path to mysite', 'path to django'] + sys.path"
> 
>
>
>
> >
>

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



multiple primary key, solution?

2009-03-04 Thread arbi

Hi all,

I read a post dating back to 2007 telling we can create a multiple
primary key using

" class Meta:
unique_together = (('field1', 'field2'),) "

in a model like

class MyModel(models.Model):
field1 = ForeignKey('table1', db_index=True)
field2 = ForeignKey('table2', db_index=True)

   class Meta:
unique_together = (('field1', 'field2'),)

Is there any updated solution? How do you do this you guys? I really
need multiple keys...

thx

Arbi
--~--~-~--~~~---~--~~
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: Accessing the development server from another machine.

2009-03-04 Thread Joe Goldthwaite

Thanks Alex.  That did something.  Now I'm getting this;

>c:\DjangoProjects\FiscalCalendar>manage.py runserver 0:8000
>Validating models...
>0 errors found
>
>Django version 1.0.2 final, using settings 'FiscalCalendar.settings'
>Development server is running at http://0:8000/
>Quit the server with CTRL-BREAK.
>Error: (11001, 'getaddrinfo failed')

I tried stepping through everything in my IDE (Komodo IDE 5.0) but I don't
get that error message.  I actually don't get anything. It just runs and
stops without outputting anything that I can see.

Stepping through the start up in the debugger makes my head hurt.


-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
On Behalf Of Alex Gaynor
Sent: Wednesday, March 04, 2009 11:44 AM
To: django-users@googlegroups.com
Subject: Re: Accessing the development server from another machine.


On 3/4/09, Joe Goldthwaite  wrote:
>
> I've been developing with the development server with the default settings
> without problems. My main development is done in a Windows virtual machine
> running on a Macbook Pro. Today I wanted to test the output with Safari.
> Since I don't have that installed in Windows, I decided to just try
> connecting with Safari from OSX to the virtual machine.  That led me to an
> adventure into the runserver settings.
>
> It looks like I should be able to just enter "manage.py runserver
> 192.168.1.117:8000" to expose the development server to the network.  When
I
> try it, it looks like it's working and I get this;
>
>>c:\DjangoProjects\FiscalCalendar>manage.py runserver 192.168.1.117:8000
>>Validating models...
>>0 errors found
>>
>>Django version 1.0.2 final, using settings 'FiscalCalendar.settings'
>>Development server is running at http://192.168.1.117:8000/
>>Quit the server with CTRL-BREAK.
>
> It looks like it's working but when I enter the address in the browser I
get
> a connection timeout error. The server never gets the request. I'm not
> running any firewall. Is there some other setting somewhere that allows
the
> development server to serve up requests to external browsers?
>
>
> >
>

Try running the server at 0:8000 this tells it to serve requests to all
hosts.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." --Voltaire
"The people's good is the highest law."--Cicero




--~--~-~--~~~---~--~~
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 primary key, solution?

2009-03-04 Thread Alex Gaynor

On 3/4/09, arbi  wrote:
>
> Hi all,
>
> I read a post dating back to 2007 telling we can create a multiple
> primary key using
>
> " class Meta:
> unique_together = (('field1', 'field2'),) "
>
> in a model like
>
> class MyModel(models.Model):
> field1 = ForeignKey('table1', db_index=True)
> field2 = ForeignKey('table2', db_index=True)
>
>class Meta:
> unique_together = (('field1', 'field2'),)
>
> Is there any updated solution? How do you do this you guys? I really
> need multiple keys...
>
> thx
>
> Arbi
> >
>

The ticket for composite ok support in django(373) has yet to be
resolved. The last work on it was done by David cramer and is I
believe available on github. That being said to my knowledge no patch
to django has ever been introduced to django that the core deva felt
was ready for inclusion.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Accessing the development server from another machine.

2009-03-04 Thread Karen Tracey
On Wed, Mar 4, 2009 at 4:51 PM, Joe Goldthwaite wrote:

>
> Thanks Alex.  That did something.  Now I'm getting this;
>
> >c:\DjangoProjects\FiscalCalendar>manage.py runserver 0:8000
> >Validating models...
> >0 errors found
> >
> >Django version 1.0.2 final, using settings 'FiscalCalendar.settings'
> >Development server is running at http://0:8000/
> >Quit the server with CTRL-BREAK.
> >Error: (11001, 'getaddrinfo failed')
>

Try 0.0.0.0:8000

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



RE: Accessing the development server from another machine.

2009-03-04 Thread Joe Goldthwaite

I don't think it's a network problem.  I've got Zope running on port 80 of
this same VM and can access it from any of the other computers.  I thought
it might be related to using a different port than 80 so I stopped Zope and
tried running the development server on 80.  That didn't work either.

This is really strange.  I always thought that when you run a server on
localhost, it accepts all requests directed to the machine it's running on.
With the Zope server, I don't define an address at all.  When I run the
server, it accepts any requests to the localhost.  It doesn't matter if I
access the machine locally using localhost or 127.0.0.1 or access it
remotely using the actual external IP address of 192.168.1.117.  It works
either way.  The Django development server must be doing something different
but I don't understand what.  How does it even know if the browser
connecting to it is coming from the local machine or some other external?
And if it does know, why would it care?

-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
On Behalf Of CLIFFORD ILKAY
Sent: Wednesday, March 04, 2009 11:38 AM
To: django-users@googlegroups.com
Subject: Re: Accessing the development server from another machine.

Joe Goldthwaite wrote:
> My main development is done in a Windows virtual machine
> running on a Macbook Pro. Today I wanted to test the output with Safari.
[snip]
> It looks like it's working but when I enter the address in the browser I
get
> a connection timeout error. The server never gets the request. I'm not
> running any firewall.

This is quite likely a problem with the network between your virtual
machine and the physical machine. With virtualization, you have multiple
ways of setting up the network between the VM and the hardware host and
not setting up a network is even an option with some virtualization
schemes so you must ensure that OS X and the Windows VM can see one
another on the network first.
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326


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



JavaScript Frameworks...

2009-03-04 Thread Kyle Hayes

In an effort to better understand loosely what developer's think of
the JavaScript frameworks they use, I've created a short survey. It is
by no means a scientific representation of an overall census,
naturally. I hope to have a somewhat broad enough audience for this
short poll.

Please share your thoughts about your favorite JavaScript framework by
filling out the following survey:
http://bit.ly/jsfw

If you are interested in the compiled results, I will be posting it at
kylehayes.info/blog

Thanks in advance, I look forward to your feedback!
-Kyle

Link to Survey: http://bit.ly/jsfw

--~--~-~--~~~---~--~~
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: CMS on Google Appengine

2009-03-04 Thread brad

On Mar 4, 9:51 am, poematrix  wrote:
> Is it possible to utilize the Django CMS on Google Appengine?

I've just starting looking into Google's App Engine as a possible
place to deploy a Django Project.  I can't answer your question
directly, but there are a couple of articles that might help you:

Running Django on Google App Engine
http://code.google.com/appengine/articles/django.html

Using Django 1.0 on App Engine with Zipimport
http://code.google.com/appengine/articles/django10_zipimport.html

There are probably more articles concerning this at the AppEngine
site:
http://code.google.com/appengine/articles/
--~--~-~--~~~---~--~~
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: Accessing the development server from another machine.

2009-03-04 Thread Joe Goldthwaite
Thanks Karen.

 

Tried it. I no longer get the "getaddrinfo failed" error message.  I'm now
able to access the server as localhost or 127.0.0.1 but no 192.168.1.117.

 

There's got to be something simple I'm missing.  This looks like it's
designed behavior.  There must be a setting somewhere. 

 

  _  

From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
On Behalf Of Karen Tracey
Sent: Wednesday, March 04, 2009 3:00 PM
To: django-users@googlegroups.com
Subject: Re: Accessing the development server from another machine.

 

On Wed, Mar 4, 2009 at 4:51 PM, Joe Goldthwaite 
wrote:


Thanks Alex.  That did something.  Now I'm getting this;

>c:\DjangoProjects\FiscalCalendar>manage.py runserver 0:8000

>Validating models...
>0 errors found
>
>Django version 1.0.2 final, using settings 'FiscalCalendar.settings'

>Development server is running at http://0:8000/

>Quit the server with CTRL-BREAK.

>Error: (11001, 'getaddrinfo failed')


Try 0.0.0.0:8000

Karen 




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Accessing the development server from another machine.

2009-03-04 Thread CLIFFORD ILKAY
Joe Goldthwaite wrote:
> I don't think it's a network problem.  I've got Zope running on port 80 of
> this same VM and can access it from any of the other computers.  I thought
> it might be related to using a different port than 80 so I stopped Zope and
> tried running the development server on 80.  That didn't work either.
> 
> This is really strange.  I always thought that when you run a server on
> localhost, it accepts all requests directed to the machine it's running on.
> With the Zope server, I don't define an address at all.

It's defined for you in zope.conf but you can change it to listen only
on localhost, a specific interface, or all interfaces.

> When I run the
> server, it accepts any requests to the localhost.  It doesn't matter if I
> access the machine locally using localhost or 127.0.0.1 or access it
> remotely using the actual external IP address of 192.168.1.117.  It works
> either way.  The Django development server must be doing something different
> but I don't understand what.  How does it even know if the browser
> connecting to it is coming from the local machine or some other external?
> And if it does know, why would it care?

The dev server is only meant for development use so the default is to
have it listen only to requests from localhost, not from any other host.
You have to explicitly specify which address(es) you want the dev server
to listen on if you want anything else.
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Accessing the development server from another machine.

2009-03-04 Thread CLIFFORD ILKAY
Joe Goldthwaite wrote:
> Tried it. I no longer get the “getaddrinfo failed” error message.  I’m
> now able to access the server as localhost or 127.0.0.1 but no
> 192.168.1.117.

What does the output of "ipconfig" on Windows and whatever the
equivalent is in OS X look like? To which machine is 192.168.1.117 bound?
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326



smime.p7s
Description: S/MIME Cryptographic Signature


RE: Accessing the development server from another machine.

2009-03-04 Thread Joe Goldthwaite

It makes sense that the dev server won't listen to other requests.  The
question is then, how to I explicitly specify which address(es) that I want
the dev server to listen on?

My ipconfig is;
Ethernet adapter Local Area Connection:

  Connection-specific DNS Suffix  . : mydomainhere.com
IP Address. . . . . . . . . . . . : 192.168.1.117
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1

c:\DjangoProjects\FiscalCalendar>

I'm sorry to be bothering everyone.  I've tried searching but I don't know
what they call that feature so I don't know what to search for.


-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
On Behalf Of CLIFFORD ILKAY
Sent: Wednesday, March 04, 2009 3:22 PM
To: django-users@googlegroups.com
Subject: Re: Accessing the development server from another machine.

Joe Goldthwaite wrote:
> I don't think it's a network problem.  I've got Zope running on port 80 of
> this same VM and can access it from any of the other computers.  I thought
> it might be related to using a different port than 80 so I stopped Zope
and
> tried running the development server on 80.  That didn't work either.
> 
> This is really strange.  I always thought that when you run a server on
> localhost, it accepts all requests directed to the machine it's running
on.
> With the Zope server, I don't define an address at all.

It's defined for you in zope.conf but you can change it to listen only
on localhost, a specific interface, or all interfaces.

> When I run the
> server, it accepts any requests to the localhost.  It doesn't matter if I
> access the machine locally using localhost or 127.0.0.1 or access it
> remotely using the actual external IP address of 192.168.1.117.  It works
> either way.  The Django development server must be doing something
different
> but I don't understand what.  How does it even know if the browser
> connecting to it is coming from the local machine or some other external?
> And if it does know, why would it care?

The dev server is only meant for development use so the default is to
have it listen only to requests from localhost, not from any other host.
You have to explicitly specify which address(es) you want the dev server
to listen on if you want anything else.
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326


--~--~-~--~~~---~--~~
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: Accessing the development server from another machine.

2009-03-04 Thread CLIFFORD ILKAY
Joe Goldthwaite wrote:
> It makes sense that the dev server won't listen to other requests.  The
> question is then, how to I explicitly specify which address(es) that I want
> the dev server to listen on?

Just like you did when you typed:

manage.py runserver 0.0.0.0:8000 (listen on port 8000 on all interfaces)

manage.py runserver 192.168.1.117:8000 (listen only on port 8000 on the
interface to which 192.168.1.117 is bound)

> My ipconfig is;
>   Ethernet adapter Local Area Connection:
> 
> Connection-specific DNS Suffix  . : mydomainhere.com
>   IP Address. . . . . . . . . . . . : 192.168.1.117
>   Subnet Mask . . . . . . . . . . . : 255.255.255.0
>   Default Gateway . . . . . . . . . : 192.168.1.1

What does the equivalent for the machine from which you're trying to
access this server when you run manage.py runserver 0.0.0.0:8000 look like?
-- 
Regards,

Clifford Ilkay
Dinamis
1419-3266 Yonge St.
Toronto, ON
Canada  M4N 3P6


+1 416-410-3326


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Appropriate placement for my testcases belonging to a non-app in Django

2009-03-04 Thread Russell Keith-Magee

On Wed, Mar 4, 2009 at 10:10 PM, madhav  wrote:
>
> I have built my website in Django. And like any other django project I
> have got apps inside the project root directory and some special
> folders like(extensions a.k.a custom django command extensions). With
> an app, we dont have any problem with having testcases. "tests.py"
> inside the app directory will be the solution. But for a special folder
> (which is not an app or which doesn't have a models.py) where do I
> place the testcases. I tried placing the tests.py inside the
> extensions directory and it said the directory is not a model and
> unable to run the tests. HOw do I solve this? How can I have a proper
> placement of testcases related to non-apps?

The trivial solution would be to piggyback your tests into the tests
module of an actual Django app. This would mean the tests for your
utility folder will get mixed in with the tests for a specific
application, but if you have a 'core/root' type application, the
confusion shouldn't be too extreme.

A slightly better solution is to make your utility folder appear to be
an application. Put an empty models.py file in your utility folder,
and add the utility folder to INSTALLED_APPS. This won't affect the
operation of Django - since there are no models, the utility folder
won't appear anywhere - but Django will be able to find the tests.

A third, slightly more complex solution would be to override the test
runner to modify the test discovery procedure. At present, the test
finder looks in the tests module for each installed app; this could
easily be modified to include other directories.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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: Is a Complex filter with __in and __exact possible?

2009-03-04 Thread Daniel Hepper

You can try this query:

Book.objects.filter(categories=1,categories=2,categories=3)

Hope that helps

-- Daniel

On 4 Mrz., 18:58, Alfonso  wrote:
> I've set up a simple filter to grab a queryset of objects matching a
> list of (many to many) categories like this:
>
> Book.objects.filter(categories__in=[1,2,3]).order_by('name').distinct
> ()
>
> It's good, it works... it returns any books in those three
> categories.But I'd like to return ONLY Books with those three
> categories?
>
> I thought something like categories__exact__in would work but clearly
> not.
>
> Any ideas?
>
> 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: New to Django and a few basic questions

2009-03-04 Thread Russell Keith-Magee

On Wed, Mar 4, 2009 at 9:54 PM, ch...@secondfoundation.net
 wrote:
>
> Hi group,
>
> as the subject says, I'm new to Django. I worked through some
> tuturials and djangobook.com for the 1.0.2 version as far as there
> already is documentation. Anyway, I'm still not certain Django is the
> right answer to my needs.
>
> What I want to do:
>
> I need to write a web based admin frontend to a OSS based mail gateway
> that consist the usual suspects (Postfix, SA, antivir, some custom
> scripts, you name it). There are already some frontends to some of
> those tools but there's always some functionality or tools missing.
>
> I need to be able to configure ALL those apps in a consistent front
> end (including the customers corporate design/identity) which
> basically means editing config textfiles (but hiding them from the
> user), (re)starting services, start scripts, show status of services,
> check input for sanity, you get it.
>
> What I have:
>
> Knowledge of  the underlaying OSS apps as mentioned above.
> Thirst for knowledge.
> I like Python.
>
> What I don't have:
>
> My programming background is, well, outdated (assembler and turbo
> pascal back in the 80s).
> SQL skill is very limited.
> HTML/CSS/webstuff knowledge not existent.
> Time is somewhat limited.
>
> My first question is, is Django the right tool to accomplish my task?

Could Django be used to implement a solution to your problem? Yes.
Django is a web framework. If you want a web interface, you can use
Django to build it. The connection to the underlying operating system
and utilities doesn't impose any particularly special constraints - it
just means you'll be making some system calls in your views. This is
well inside the realm of the possible.

Is it the best tool for the task? It's at least as good as any other
web framework for building web applications. However, a web consoles
for admin tasks isn't a new idea. There are dozens of examples in the
wild - most ISPs and web hosting companies will provide some sort of
web interface to their system. Google is your friend - I'd be
surprised if you couldn't find a dozen pre-canned examples for this
sort of web interface.

However if your requirements are particularly customized, or you have
a hankering to do this yourself: you have admitted to limited
programming background, no SQL skills, no HTML/CSS skills. Regardless
of the platform you choose (Django or otherwise), you're going to have
a learning curve.

You then say you have no time, either.

My first recommendation would be to take a hard look at your
expectations. Something is going to have to give. Either you need to
extend your deadline to give you more time to skill up, or reduce your
feature set so you have less to accomplish, or find someone who
already has the knowledge who can build the system for you.

> I'm a bit uncertain. If yes, are there any Django apps I could use for
> template/guideline that already do what I need? If Django is not what
> I need, are there any recommendations considering my state of
> knowledge?

I can't say I know of an "out of the box" Django solution for this
problem - but it wouldn't surprise me if there is one out there
somewhere. Again, Google is your friend.

If you really want to build this yourself, given your state of
knowledge, Django will be as good an option as any. You're going to
need to learn how to program, how the web works, how HTML/CSS works...
no matter which web framework you choose, you're going to need to
learn these things. My suggestion would be to avoid the temptation to
try rushing right to your solution. Work through some tutorials,
tinker around a bit, get a feel for the tools that are available. Once
you have a feel for the basics, hopefully the road to your final
solution will be a little more obvious.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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: extending admin change_form template

2009-03-04 Thread Jon Reck
Thank you so much. Works like a charm.
Print
Labels

-Jon

On Wed, Mar 4, 2009 at 1:18 PM, AmanKow  wrote:

>
> On Mar 3, 10:50 am, Jon Reck  wrote:
> > I'm a novice Python and Django programmer so please don't assume a lot of
> > knowledge here.
> > I'm trying to place a link on an admin change form to a label printing
> > function. I'd like to pass the id of the current record to the function.
> If
> > I hardwire it in (see below- record number = 920) it works. I can't
> figure
> > out how to code this so the current record number is inserted by the
> > program. Is there some sort of template variable that I can use for this?
> Or
> > can you suggest a better approach?
> >
> > thanks , Jon
> >
> > {% extends "admin/change_form.html" %}
> > {% load i18n %}
> > {% block after_field_sets %}
> > Print Labels
> > {% endblock %}
>
> I believe that the object id for the current object is passed in the
> context in object_id.
>
> You can see it in use in the history link rendering in admin/
> change_form.html:
> href="../../../r/{{ content_type_id }}/{{ object_id }}/"
>
> Wayne
>

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



Why serializing to JSON doesn't work?

2009-03-04 Thread Marek Wawrzyczek

Hello,

I've got the code like this:

from django.core import serializers
...

ret = { }
ret['a'] = 'b'
json_serializer = serializers.get_serializer("json")()
serialized = json_serializer.serialize(ret, ensure_ascii=False)
print serialized

and this doesn't print serialized. What do I do wrong ?
I'm using Python 2.5.2, Django 1.0.2.

Thanks in advance,
Marek

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



AttributeError: 'module' object has no attribute 'TabularInline'

2009-03-04 Thread D

I was getting this error
AttributeError: 'module' object has no attribute 'TabularInline'
with code i knew was good,

After a bit of digging i found my own answer ... posted here for
anyone who googles the error message;

My dev server version of django was ;
python -c "import django; print django.get_version()"
1.0.2 final

The broken server;
0.97-pre-SVN-7862

Once i updated it, it all works fine.

Hope this helps someone,

D

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



Overriding the HTML id in ModelForm

2009-03-04 Thread Romain

Hello,

On the same page I have 2 ModelForm that happen to have an attribute
with the same name. Is it possible to choose the name of the HTML id
generated by the form without having to change the real name of the
model attribute?

e.g.
class A(models.Model):
  amount = models.IntegerField()

class B(models.Model):
  amount = models.IntegerField()


class AForm(ModelForm):
  class Meta:
model = A

class BForm(ModelForm):
  class Meta:
model = B

Conflict of ids when forms printed:
...

...

...

Thanks a lot,

Romain

--~--~-~--~~~---~--~~
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: Three Physical Tiers

2009-03-04 Thread Ishwor Gurung
Hi

ruffeo wrote:
> Does anyone know how to develop a complex django project in a 3 tiered
> network environment, still using the MCV architecture?
> 
> I.E. Web Server (view and control code), App Server (model code), and
> Database Server

model- representation that needs to be modeled into the db (data model
e.g models.py)

template- your user-facing code so it differentiates how your data is
presented (e.g templates/*)

view- maps your uri specific code to callback functions (e.g in
views.py) which should be resolvable by the URLResolver (to be defined
in URLConf)

MTV - this is what Django calls MVC (in that order)

DB - Django's "python manage.py syncdb" pulls the class definition from
the Model (e.g. models.py) and then inserts them into the DB. This ORM
design is really powerful as we get db<->application_code mapping
essentially for free. A DB can be another tier here that exists seperately.

Web server - Apache, FastCGI, any WSGI-compliant server etc.. (Django
provides lightweight devel server too)

On the topic of Application server, Djangobook.com puts it really nicely -
"At its core, the philosophy of shared nothing is really just the
application of loose coupling to the entire software stack. This
architecture arose in direct response to what was at the time the
prevailing architecture: a monolithic Web application server that
encapsulates the language, database, and Web server — even parts of the
operating system — into a single process (e.g., Java)."[1]

Others could possibly add more to your query (because I've yet to learn
Django properly myself) but from what I've understood Django does not
need a app server!

Cheers,
Ishwor

[1] http://www.djangobook.com/en/1.0/chapter20/





smime.p7s
Description: S/MIME Cryptographic Signature


Re: opposite of icontains

2009-03-04 Thread Jeff FW

You'd have to split() the string (probably on spaces, though I don't
know exactly what you're going for,) then build a query that checks
for each piece OR'd with every other piece.  That would probably be
the best way--check out:
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

A simpler way (also naive) would be this:
Entry.objects.filter(headline__in='Today Lennon Honoured'.split())

If you decide to go with the first approach, let me know--I can help
you with the syntax.

-Jeff

On Mar 4, 8:01 am, koranthala  wrote:
> Hi,
>      How do I implement a substring query?
>      Please find the example below.
> From Django Documentation:
>   Entry.objects.get(headline__icontains='Lennon')
>   => This matches the headline 'Today lennon honoured'
>
> My query is the opposite:
>    I have the string 'Lennon' inside my DB, and I have to match 'Today
> Lennon honoured'
> Say:
> Entry.objects.get(headline__isubstring='Today Lennon Honoured')
> should return headline 'Lennon'.
>
>     I checked iregex too, but I cannot seem to solve it myself. If
> somebody has solved this, could you please help me out.
--~--~-~--~~~---~--~~
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: opposite of icontains

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 05:01 -0800, koranthala wrote:
> Hi,
>  How do I implement a substring query?
>  Please find the example below.
> From Django Documentation:
>   Entry.objects.get(headline__icontains='Lennon')
>   => This matches the headline 'Today lennon honoured'
> 
> My query is the opposite:
>I have the string 'Lennon' inside my DB, and I have to match 'Today
> Lennon honoured'
> Say:
> Entry.objects.get(headline__isubstring='Today Lennon Honoured')
> should return headline 'Lennon'.
> 
> I checked iregex too, but I cannot seem to solve it myself. If
> somebody has solved this, could you please help me out.

This isn't the type of searching operating that is going to be standard
outside of specialised packages. It's actually a really hard problem
(not impossible, there are solutions, but hard) in general. The
complexity comes from the fact that the match could start anywhere and
involve any number of characters. So to do this efficiently requires
some special datastructures (with suffix trees and some other
structures, you can the search in about O(total length of text)).

Now, I'm sure it wouldn't be impossible to write, say, an extension for,
say, PostgreSQL (picking that database because of its excellent support
for extensions) that supported this kind of searching, but it would be a
fair bit of work. It would require a particular sort of index structure
to support the searches. I don't know any package off the top of my head
that does this for databases. Might be a fun project for somebody with a
bit of time and curiosity.

I've done this kind of thing in the past for a couple of clients and
I've always pulled the text to be searched into memory. Create a data
structure of all the headlines to be searched (using your example) and
then match the search string against them to find the longest common
substring match. There's a lot of literature on this sort of stuff, and
searching for things like "longest common substring" will give you a
place to start.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Why serializing to JSON doesn't work?

2009-03-04 Thread Jeff FW

The serializers are for serializing querysets/models.  I'm surprised
you're not getting an error message there--are you catching all
exceptions?

What you want is in django.utils.simplejson:

from django.utils.simplejson import encoder
encoder.JSONEncoder().encode(ret)

-Jeff

On Mar 4, 6:55 pm, Marek Wawrzyczek  wrote:
> Hello,
>
> I've got the code like this:
>
>     from django.core import serializers
>     ...
>
>     ret = { }
>     ret['a'] = 'b'
>     json_serializer = serializers.get_serializer("json")()
>     serialized = json_serializer.serialize(ret, ensure_ascii=False)
>     print serialized
>
> and this doesn't print serialized. What do I do wrong ?
> I'm using Python 2.5.2, Django 1.0.2.
>
> Thanks in advance,
> Marek
--~--~-~--~~~---~--~~
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: delete items in queryset results?

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 07:39 -0800, adrian wrote:
> 
> I ended up doing the following:
> 
> 1. raw SQL to get the IDs of the rows I want.   This required an SQL
> statement with an inner JOIN subquery specifically:
> 
> SELECT f.id, f.species_name, f.date from (select species_name, max
> (date) as maxdate from lister_importedsighting GROUP BY species_name)
> as x inner join lister_importedsighting as f on f.species_name =
> x.species_name and f.date = x.maxdate
> 
> 2. Then used the result of that to filter a QuerySet using:
> 
>   results = my_custom_sql(sql)
>   id_list = []
>   for row in results:
> id_list.append(row[0])
>   query_set = query_set.filter(id__in=id_list)

So here's an advanced Django tip that might help you make this a little
more natural the next time. It only works on current Django trunk (and
in the upcoming Django 1.1), not in Django 1.0.x. It's kind of public
API, although not documented yet, because I'm letting it settle down for
a while. Unlikely to change significantly, however.

The rvalue (right-hand side value) you give to a filter (think of it as
"filter(key=rvalue)") can be a smart object of some kind. If it has a
method called "as_sql", that method will be called to create the SQL
used in the query.

Therefore, you could create an object that returns the SQL for a list of
ID values in response to the call to as_sql(), and Django will insert
that SQL into the query it creates. Make sure that you only return a
single value in the SELECT clause (e.g. SELECT id...) and make sure that
you use aliases which won't clash with Django's table aliases. Django's
aliases all look like a single capital letter followed by a number (e.g.
"T0", "U1", "U2"). So if you make your aliases start with more than one
letter, you'll have no clashes.

If you're interested in trying this out and are debugging what's going
on, the relevant code for creating this SQL is in
django/db/models/fields/__init__.py, in the Field.get_db_prep_lookup()
method.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Three Physical Tiers

2009-03-04 Thread ruffeo

This was extremely helpful. What about the need to protect the
database from intrusion? Since there is only one hop from the
webserver to the database server (2 tiers). At my job, the school of
thought is that the middle tier is the only server that can access the
database (ip restriction) which is exposed through webservices.That
way there are 3 physical tiers (web, app code, data).  I am trying to
apply the same concepts using Django framework.


On Mar 4, 7:58 pm, Ishwor Gurung  wrote:
> Hi
>
> ruffeo wrote:
> > Does anyone know how to develop a complex django project in a 3 tiered
> > network environment, still using the MCV architecture?
>
> > I.E. Web Server (view and control code), App Server (model code), and
> > Database Server
>
> model- representation that needs to be modeled into the db (data model
> e.g models.py)
>
> template- your user-facing code so it differentiates how your data is
> presented (e.g templates/*)
>
> view- maps your uri specific code to callback functions (e.g in
> views.py) which should be resolvable by the URLResolver (to be defined
> in URLConf)
>
> MTV - this is what Django calls MVC (in that order)
>
> DB - Django's "python manage.py syncdb" pulls the class definition from
> the Model (e.g. models.py) and then inserts them into the DB. This ORM
> design is really powerful as we get db<->application_code mapping
> essentially for free. A DB can be another tier here that exists seperately.
>
> Web server - Apache, FastCGI, any WSGI-compliant server etc.. (Django
> provides lightweight devel server too)
>
> On the topic of Application server, Djangobook.com puts it really nicely -
> "At its core, the philosophy of shared nothing is really just the
> application of loose coupling to the entire software stack. This
> architecture arose in direct response to what was at the time the
> prevailing architecture: a monolithic Web application server that
> encapsulates the language, database, and Web server — even parts of the
> operating system — into a single process (e.g., Java)."[1]
>
> Others could possibly add more to your query (because I've yet to learn
> Django properly myself) but from what I've understood Django does not
> need a app server!
>
> Cheers,
> Ishwor
>
> [1]http://www.djangobook.com/en/1.0/chapter20/
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
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: translating app name ... again

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 09:39 -0800, patrickk wrote:
> so far, it doesn´t seem possible to translate the app-names within the
> admin-interface, which results in a strange index-site with mixed
> languages.
> 
> any updates on this issue? any ideas?

If you put each of your app names into a file that was then processed by
makemessages (so the strings were included in the PO file) and then
translated them, I believe the translated version will show up on the
site (the app name is certainly marked as "to be translated" in the
template). So you need to write down the app names by hand.

Right now, there's no automatic extraction of application names. No
great plans to do so either (although if somebody came along with an
ideal setup, we'd certainly include it). Hacks aren't interesting -- we
need a decent, robust solution and are prepared to wait until that
appears. It's one of those cases where localisation has to compromise to
code, instead of the other way around.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: simple model problem

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 10:43 -0800, arbi wrote:
> Hello,
> I am new to Django and programming...
> I have a model similar to this one :
> 
> class myModel :
>   attribute 1 = models.ForeignKey(myModel2, primary_key = True)
>   attribute 2 = models.ForeignKey(myModel3, primary_key = True)
> 
> is it possible to have two primary keys?

No. One primary key per model.

> In fact I want that the id of an instance of this class is the
> concatenation of the (attribute 1 +attribute2).
> How to do this?

You might be able to do it with a custom field type and fair bit of
code. However, this is definitely not the approach to take if you are
just starting out.

Instead, just let the primary key be the default one Django provides you
with. You can have another property or method on the model that creates
your combined value that you can use for other purposes. Trying to
overly control the primary key almost always is not necessary.

What is the problem you are really trying to solve here?

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: formset of ModelForms missing functionality?

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 11:44 -0800, Margie wrote:
> Hi Malcolm.  So after reviewing your pointers, I had high hopes of
> being able to move to using the modelformset_factory, but I still seem
> to have problems.  The problem I run into is that when _construct_form
> (the one in django/forms/models.py) is called, it tries to do this:
> 
> if i < self._initial_form_count:
> kwargs['instance'] = self.get_queryset()[i]
> 
> I have no objects of my model yet and get_queryset()  returns
> self._queryset, which is [].  The above [i] index then causes a 'list
> index out of range exception'.  I think this was what I first
> encountered which made me think that I had to have a queryset to use
> modelformset_factory.

That second line of code will only be executed if
self._initial_form_count is greater than 0. You aren't providing any
initial forms, so it should be zero.

Looking at the source (it's set in the BaseFormset.__init__ method), it
will only be non-zero if you supply initial data, which kind of makes
sense, since providing initial data for "extra" forms would mean you'd
always end up creating a new record every time you viewed and submitted
that form. I can see why it's set up that way, although it confirms my
wish to spend a couple of days going over the formsets documentation
with a two-by-four.

I think it means that supplying this tile id via initial data is
probably not a great idea, as it will inadvertently create new records
own the track. I'd kind of been thinking that approach might have been a
little clunky, anyway, so this backs up that hunch. I'll put some more
details in the formset initialization thread, because it's probably more
appropriate there.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Overriding the HTML id in ModelForm

2009-03-04 Thread Eric Abrahamsen


On Mar 5, 2009, at 8:05 AM, Romain wrote:

>
> Hello,
>
> On the same page I have 2 ModelForm that happen to have an attribute
> with the same name. Is it possible to choose the name of the HTML id
> generated by the form without having to change the real name of the
> model attribute?

A simple solution would be to instantiate your ModelForms with a prefix:
http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms

Another, finer-grained choice is using the auto_id argument:
http://docs.djangoproject.com/en/dev/ref/forms/api/#configuring-html-label-tags

Hope that's what you're looking for,

Eric

>
> e.g.
> class A(models.Model):
>  amount = models.IntegerField()
>
> class B(models.Model):
>  amount = models.IntegerField()
>
>
> class AForm(ModelForm):
>  class Meta:
>model = A
>
> class BForm(ModelForm):
>  class Meta:
>model = B
>
> Conflict of ids when forms printed:
> ...
> 
> ...
> 
> ...
>
> Thanks a lot,
>
> Romain
>
> >


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



Possible bug in admin?

2009-03-04 Thread Julien Phalip

Hi,

I can't find the exact cause of this, but it seems as though something
has changed in the admin's email widget.

For one of my project I just upgraded Django from revision 9294 to
9975.

Symptomatically, with the recent version, the email field doesn't have
the CSS class 'vTextField', which means it looks smaller than the
other text fields in the form.

Do you know if that's by design or if that's an oversight?

For now, a quick fix is to do something like this in my code:

class MyModelAdmin(ModelAdmin):

def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.attname == 'email':
kwargs['widget'] = AdminTextInputWidget() # Have to do
that, otherwise the email field is bizarrely small (it doesn't have
the 'vTextField' class)...
return super(MyModelAdmin, self).formfield_for_dbfield
(db_field, **kwargs)

Thanks a lot,

Julien
--~--~-~--~~~---~--~~
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: Three Physical Tiers

2009-03-04 Thread Mike Ramirez
On Wednesday 04 March 2009 05:43:41 pm ruffeo wrote:
> This was extremely helpful. What about the need to protect the
> database from intrusion? Since there is only one hop from the
> webserver to the database server (2 tiers). At my job, the school of
> thought is that the middle tier is the only server that can access the
> database (ip restriction) which is exposed through webservices.That
> way there are 3 physical tiers (web, app code, data).  I am trying to
> apply the same concepts using Django framework.
>

It sounds like you're trying to stop outside direct connections to the 
database server. Which can be accomplished in a 2 or more tier configuration. 
By having the database server (to clarify, database server refers to the 
software, ie. MySQL, postgres, etc...) configured to listen for incoming 
request from a white list of ip's (webservers, dba's, etc...).  It is that 
simple, in addition to configuring the rest of the server correctly.  Though 
it is probably better to have the actual database server only on the lan and 
never directly on the internet.   

In a 3 tier system, you want the first tier to be the web server proxy/load 
balancer, where you have  apache configured with mod_evasive, mod_security 
and mod_proxy. mod_proxy sends/recieves (as a reverse proxy) the request 
to/from your 'app server', which holds your django+project+httpd server 
configuration, the middle tier. The middle tier is only configured like the 
database with a white list of ips and should not reside on the internet, only 
in a lan that the proxy handles connections for.  The third tier of course is 
the database configured with it's whitelist.

Here is an article on configuring the first tier server:
 
http://linuxadministration.wordpress.com/2007/09/06/advance-apache-security-mod_proxymod_securitymod_evasive/

You should also make the first tier server your media server for website in 
addition to the security proxy.  Serving your css/js/image files as per the 
django docs (see MEDIA_URL && MEDIA_ROOT in the django settings, in addition 
to serving static files and handling file uploads).

The idea of it having to be a 3 tier system is really not that important. The 
two tier system can work the same way, and be just as secure with the correct 
server configurations. 

Mike

-- 
Magically turning people's old scalar contexts into list contexts is a
recipe for several kinds of disaster.
 -- Larry Wall in <199709291631.jaa08...@wall.org>


signature.asc
Description: This is a digitally signed message part.


New version of open source Django stack appliance

2009-03-04 Thread Liraz

Hello everyone,

We just released a new version of our Django stack appliance:

http://www.turnkeylinux.org/appliances/django

Changes include:

* Security: SSL support, crypto key regeneration during installation,
  database password setting during installation.

* Usability: confconsole support for systems with multiple NICs,
  password-free login in demo mode, added many generically useful
Webmin
  modules, and improved embedded documentation.

* A bugfix in the daily auto-updates mechanism.

* rebuilt on top of TurnKey Core, the new common base for all software
  appliances, which is assembled from Ubuntu 8.04.2 LTS packages.

Cheers,
Liraz
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ModelAdmin get_urls w/ invalid literal for int() with base 10

2009-03-04 Thread Brian Neal

I'd like to make my own custom view. In the past I did this by
following the django book and added a URL to my main urlpatterns above
the '^admin/(.*)' pattern. But I noticed a new get_urls function on
the ModelAdmin class in the docs. I'm on trunk, and just did an svn
update to 9975 to try this out.

The docs for get_urls show the view being registered as self.view. Is
that possible to register a class method as a view?

Anyway, just to try things out, I created a view function right in my
admin.py file, and my admin.py file looks like this:

http://dpaste.com/6643/

I'm kind of guessing here about the URL I need to visit to trigger
this new view. My model lives at admin/gcalendar/event, so I'm
guessing I need to visit admin/gcalendar/event/my_view. When I do
that, I get this error:

ValueError at /admin/gcalendar/event/my_view/

invalid literal for int() with base 10: 'my_view'

With this traceback:  http://dpaste.com/6649/

For reference, here is my models.py:  http://dpaste.com/6650/

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: Overriding the HTML id in ModelForm

2009-03-04 Thread Alex Gaynor

On 3/4/09, Eric Abrahamsen  wrote:
>
>
> On Mar 5, 2009, at 8:05 AM, Romain wrote:
>
>>
>> Hello,
>>
>> On the same page I have 2 ModelForm that happen to have an attribute
>> with the same name. Is it possible to choose the name of the HTML id
>> generated by the form without having to change the real name of the
>> model attribute?
>
> A simple solution would be to instantiate your ModelForms with a prefix:
> http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms
>
> Another, finer-grained choice is using the auto_id argument:
> http://docs.djangoproject.com/en/dev/ref/forms/api/#configuring-html-label-tags
>
> Hope that's what you're looking for,
>
> Eric
>
>>
>> e.g.
>> class A(models.Model):
>>  amount = models.IntegerField()
>>
>> class B(models.Model):
>>  amount = models.IntegerField()
>>
>>
>> class AForm(ModelForm):
>>  class Meta:
>>model = A
>>
>> class BForm(ModelForm):
>>  class Meta:
>>model = B
>>
>> Conflict of ids when forms printed:
>> ...
>> 
>> ...
>> 
>> ...
>>
>> Thanks a lot,
>>
>> Romain
>>
>> >
>
>
> >
>

Auto_I'd won't help. The issue is the names conflict in the POST so
this is an issue for prefix.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Is a Complex filter with __in and __exact possible?

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 15:06 -0800, Daniel Hepper wrote:
> You can try this query:
> 
> Book.objects.filter(categories=1,categories=2,categories=3)
> 
> Hope that helps

It won't. A filter() method is a normal Python function or method call.
You can only specify each keyword argument exactly once. Because of the
way Django implements queryset methods, only the last keyword argument
will be used (no error will be raised), but it's still not what is
expected.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Possible bug in admin?

2009-03-04 Thread Alex Gaynor

On 3/4/09, Julien Phalip  wrote:
>
> Hi,
>
> I can't find the exact cause of this, but it seems as though something
> has changed in the admin's email widget.
>
> For one of my project I just upgraded Django from revision 9294 to
> 9975.
>
> Symptomatically, with the recent version, the email field doesn't have
> the CSS class 'vTextField', which means it looks smaller than the
> other text fields in the form.
>
> Do you know if that's by design or if that's an oversight?
>
> For now, a quick fix is to do something like this in my code:
>
> class MyModelAdmin(ModelAdmin):
>
> def formfield_for_dbfield(self, db_field, **kwargs):
> if db_field.attname == 'email':
> kwargs['widget'] = AdminTextInputWidget() # Have to do
> that, otherwise the email field is bizarrely small (it doesn't have
> the 'vTextField' class)...
> return super(MyModelAdmin, self).formfield_for_dbfield
> (db_field, **kwargs)
>
> Thanks a lot,
>
> Julien
> >
>

It's a suckasding issue. There is a ticket with a patch open about it.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
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: Is a Complex filter with __in and __exact possible?

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 09:58 -0800, Alfonso wrote:
> I've set up a simple filter to grab a queryset of objects matching a
> list of (many to many) categories like this:
> 
> Book.objects.filter(categories__in=[1,2,3]).order_by('name').distinct
> ()
> 
> It's good, it works... it returns any books in those three
> categories.But I'd like to return ONLY Books with those three
> categories?

There are two different versions of this question. One of them is
possible, the other probably not just yet (at least, I haven't worked
out a neat answer).

First version: I want books that are in all three categories (plus
possibly some extra ones):

Answer: Relies on using Django trunk (or the upcoming Django 1.1), since
it uses aggregation/annotations.

from django.db.models import Count

Book.objects.filter(categories__in=[1, 2, 
3]).annotate(num_cats=Count('categories').filter(num_cats=3)

Second version: I want books that are in all three categories, but just
those three categories and *no others*.

Answer: hmmm... :-(

This one is possible in raw SQL, but it's a fairly fiddly query. I can't
make it work with annotate() yet, although I just played around for
about 30 minutes to see what was going on. It might be a subtle
limitation in annotate(), but that's only a new feature, so we can
extend it in the future. Basically, the count I do in the first answer
counts the number of categories that have been selected, not the total
number of categories available for each book (which would require some
extra table joins). I'd also want to filter on the total number of
categories available in this version of the question, so I get stuck.

Still, I suspect you want the first version of the question, which has
the "simple" solution I've given.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: Is a Complex filter with __in and __exact possible?

2009-03-04 Thread Malcolm Tredinnick

On Thu, 2009-03-05 at 14:19 +1100, Malcolm Tredinnick wrote:
[...]
> Second version: I want books that are in all three categories, but just
> those three categories and *no others*.
> 
> Answer: hmmm... :-(
> 
> This one is possible in raw SQL, but it's a fairly fiddly query. I can't
> make it work with annotate() yet, although I just played around for
> about 30 minutes to see what was going on. It might be a subtle
> limitation in annotate(), but that's only a new feature, so we can
> extend it in the future. Basically, the count I do in the first answer
> counts the number of categories that have been selected, not the total
> number of categories available for each book (which would require some
> extra table joins). I'd also want to filter on the total number of
> categories available in this version of the question, so I get stuck.

So, naturally, as soon as I hit "send", the solution occurs to me. Not
short, but it works. Here's how to get all books that are in precisely
those three categories: no more and no less (line breaks inserted for
readability, hopefully):

Book.objects.
   filter(categories__in=[1, 2, 3]).
   annotate(num_cats=Count('categories').
   filter(num_cats=3).
   exclude(id__in=
  Book.objects.annotate(all_cats=Count('categories')).
 filter(all_cats__gt=3))


It's a pretty ugly SQL query and I haven't put in the time to work out
if it's the most efficient we can do. But it does the right thing.
Again, requires Django 1.1-alpha because it relies on annotations and
nested querysets.

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Possible bug in admin?

2009-03-04 Thread Julien Phalip

On Mar 5, 2:16 pm, Alex Gaynor  wrote:
> On 3/4/09, Julien Phalip  wrote:
> > Hi,
>
> > I can't find the exact cause of this, but it seems as though something
> > has changed in the admin's email widget.
>
> > For one of my project I just upgraded Django from revision 9294 to
> > 9975.
>
> > Symptomatically, with the recent version, the email field doesn't have
> > the CSS class 'vTextField', which means it looks smaller than the
> > other text fields in the form.
>
> > Do you know if that's by design or if that's an oversight?
>
> > For now, a quick fix is to do something like this in my code:
>
> > class MyModelAdmin(ModelAdmin):
>
> >     def formfield_for_dbfield(self, db_field, **kwargs):
> >         if db_field.attname == 'email':
> >             kwargs['widget'] = AdminTextInputWidget() # Have to do
> > that, otherwise the email field is bizarrely small (it doesn't have
> > the 'vTextField' class)...
> >         return super(MyModelAdmin, self).formfield_for_dbfield
> > (db_field, **kwargs)
>
> > Thanks a lot,
>
> > Julien
>
> It's a suckasding issue. There is a ticket with a patch open about it.
>
> Alex


Hi Alex,

I did search the ticket system and this list before posting but
couldn't find any reference to this issue. Would be great if you could
point me out to which ticket it is.

Thanks a lot,

Julien
--~--~-~--~~~---~--~~
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: Possible bug in admin?

2009-03-04 Thread Alex Gaynor



On Mar 4, 2009, at 10:33 PM, Julien Phalip  wrote:

>
> On Mar 5, 2:16 pm, Alex Gaynor  wrote:
>> On 3/4/09, Julien Phalip  wrote:
>>> Hi,
>>
>>> I can't find the exact cause of this, but it seems as though  
>>> something
>>> has changed in the admin's email widget.
>>
>>> For one of my project I just upgraded Django from revision 9294 to
>>> 9975.
>>
>>> Symptomatically, with the recent version, the email field doesn't  
>>> have
>>> the CSS class 'vTextField', which means it looks smaller than the
>>> other text fields in the form.
>>
>>> Do you know if that's by design or if that's an oversight?
>>
>>> For now, a quick fix is to do something like this in my code:
>>
>>> class MyModelAdmin(ModelAdmin):
>>
>>> def formfield_for_dbfield(self, db_field, **kwargs):
>>> if db_field.attname == 'email':
>>> kwargs['widget'] = AdminTextInputWidget() # Have to do
>>> that, otherwise the email field is bizarrely small (it doesn't have
>>> the 'vTextField' class)...
>>> return super(MyModelAdmin, self).formfield_for_dbfield
>>> (db_field, **kwargs)
>>
>>> Thanks a lot,
>>
>>> Julien
>>
>> It's a suckasding issue. There is a ticket with a patch open about  
>> it.
>>
>> Alex
>
>
> Hi Alex,
>
> I did search the ticket system and this list before posting but
> couldn't find any reference to this issue. Would be great if you could
> point me out to which ticket it is.
>
> Thanks a lot,
>
> Julien
> >

Unfortunately I'm on a horrible setup right now but if you check for  
tickets assigned to me(Alex) it should jump out.

Alex

--~--~-~--~~~---~--~~
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: Possible bug in admin?

2009-03-04 Thread Julien Phalip

On Mar 5, 2:40 pm, Alex Gaynor  wrote:
> On Mar 4, 2009, at 10:33 PM, Julien Phalip  wrote:
>
>
>
>
>
> > On Mar 5, 2:16 pm, Alex Gaynor  wrote:
> >> On 3/4/09, Julien Phalip  wrote:
> >>> Hi,
>
> >>> I can't find the exact cause of this, but it seems as though  
> >>> something
> >>> has changed in the admin's email widget.
>
> >>> For one of my project I just upgraded Django from revision 9294 to
> >>> 9975.
>
> >>> Symptomatically, with the recent version, the email field doesn't  
> >>> have
> >>> the CSS class 'vTextField', which means it looks smaller than the
> >>> other text fields in the form.
>
> >>> Do you know if that's by design or if that's an oversight?
>
> >>> For now, a quick fix is to do something like this in my code:
>
> >>> class MyModelAdmin(ModelAdmin):
>
> >>>     def formfield_for_dbfield(self, db_field, **kwargs):
> >>>         if db_field.attname == 'email':
> >>>             kwargs['widget'] = AdminTextInputWidget() # Have to do
> >>> that, otherwise the email field is bizarrely small (it doesn't have
> >>> the 'vTextField' class)...
> >>>         return super(MyModelAdmin, self).formfield_for_dbfield
> >>> (db_field, **kwargs)
>
> >>> Thanks a lot,
>
> >>> Julien
>
> >> It's a suckasding issue. There is a ticket with a patch open about  
> >> it.
>
> >> Alex
>
> > Hi Alex,
>
> > I did search the ticket system and this list before posting but
> > couldn't find any reference to this issue. Would be great if you could
> > point me out to which ticket it is.
>
> > Thanks a lot,
>
> > Julien
>
> Unfortunately I'm on a horrible setup right now but if you check for  
> tickets assigned to me(Alex) it should jump out.
>
> Alex

Ok, thanks. I assume it's #10059.

Julien
--~--~-~--~~~---~--~~
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: formset of ModelForms missing functionality?

2009-03-04 Thread Margie

Yes, I agree with what you are saying about self._initial_form_count
being set to a number greater than zero due to me using initial in my
code that creates the formset, as follows:

def makeTaskDetailFormSetForCreate(tileList, data=None):
TaskDetailFormSet = modelformset_factory(TaskDetail,
 form=TaskDetailForm,
 
formset=TaskDetailCustomBaseFormSetForCreate)

taskDetailFormSet = TaskDetailFormSet(data=data,
  tiles=tileList,
  initial=[{"tile":tile.id}
for tile in tileList])

return taskDetailFormSet

But if I don't use initial - how do I create the initial values for
the forms?  I thought using initial is the "right" way to do it?  And
of course, as I described in the formset initialization thread, when I
don't use initial and I instead try setting it in the init for the
form, like this:

class TaskDetailForm(forms.ModelForm):
class Meta:
model=TaskDetail
exclude=('task')

def __init__(self, tile, *args, **kwargs):
super(TaskDetailForm, self).__init__(*args, **kwargs)
self.fields['tile'].initial = tile.id

I seem to have a different set of problems related to cleaned_data not
getting set correctly.  I guess these two threads are converging -
I'll look for your response there.

By the way, you may have noticed that in some cases my code has
TaskTileDetail while in others it is TaskDetail.  I tried shortening
the name for the purpose of the posting, and ended up missing some
when I did the cut and paste, sorry for any added confusion from that.

Margie




On Mar 4, 6:09 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2009-03-04 at 11:44 -0800, Margie wrote:
> > Hi Malcolm.  So after reviewing your pointers, I had high hopes of
> > being able to move to using the modelformset_factory, but I still seem
> > to have problems.  The problem I run into is that when _construct_form
> > (the one in django/forms/models.py) is called, it tries to do this:
>
> >         if i < self._initial_form_count:
> >             kwargs['instance'] = self.get_queryset()[i]
>
> > I have no objects of my model yet and get_queryset()  returns
> > self._queryset, which is [].  The above [i] index then causes a 'list
> > index out of range exception'.  I think this was what I first
> > encountered which made me think that I had to have a queryset to use
> > modelformset_factory.
>
> That second line of code will only be executed if
> self._initial_form_count is greater than 0. You aren't providing any
> initial forms, so it should be zero.
>
> Looking at the source (it's set in the BaseFormset.__init__ method), it
> will only be non-zero if you supply initial data, which kind of makes
> sense, since providing initial data for "extra" forms would mean you'd
> always end up creating a new record every time you viewed and submitted
> that form. I can see why it's set up that way, although it confirms my
> wish to spend a couple of days going over the formsets documentation
> with a two-by-four.
>
> I think it means that supplying this tile id via initial data is
> probably not a great idea, as it will inadvertently create new records
> own the track. I'd kind of been thinking that approach might have been a
> little clunky, anyway, so this backs up that hunch. I'll put some more
> details in the formset initialization thread, because it's probably more
> appropriate there.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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: ModelAdmin get_urls w/ invalid literal for int() with base 10

2009-03-04 Thread Brian Neal

On Mar 4, 9:11 pm, Brian Neal  wrote:
> I'd like to make my own custom view. In the past I did this by
> following the django book and added a URL to my main urlpatterns above
> the '^admin/(.*)' pattern. But I noticed a new get_urls function on
> the ModelAdmin class in the docs. I'm on trunk, and just did an svn
> update to 9975 to try this out.
>
> The docs for get_urls show the view being registered as self.view. Is
> that possible to register a class method as a view?
>
> Anyway, just to try things out, I created a view function right in my
> admin.py file, and my admin.py file looks like this:
>
> http://dpaste.com/6643/
>
> I'm kind of guessing here about the URL I need to visit to trigger
> this new view. My model lives at admin/gcalendar/event, so I'm
> guessing I need to visit admin/gcalendar/event/my_view. When I do
> that, I get this error:
>
> ValueError at /admin/gcalendar/event/my_view/
>
> invalid literal for int() with base 10: 'my_view'
>
> With this traceback:  http://dpaste.com/6649/
>
> For reference, here is my models.py:  http://dpaste.com/6650/
>
> Thanks!

I put an assert in my get_urls() function and it was not getting hit.
I made sure that my Django contrib/admin/options.py file does indeed
have the get_urls() function.
I deleted all the *.pyc files under site-packages/django and redid the
'sudo python setup.py install' step.
Still no go. I think it is just trying the last default pattern in the
base ModelAdmin get_urls() and choking on that.

--~--~-~--~~~---~--~~
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: formset of ModelForms missing functionality?

2009-03-04 Thread Malcolm Tredinnick

On Wed, 2009-03-04 at 19:47 -0800, Margie wrote:
> Yes, I agree with what you are saying about self._initial_form_count
> being set to a number greater than zero due to me using initial in my
> code that creates the formset, as follows:
> 
> def makeTaskDetailFormSetForCreate(tileList, data=None):
> TaskDetailFormSet = modelformset_factory(TaskDetail,
>  form=TaskDetailForm,
>  
> formset=TaskDetailCustomBaseFormSetForCreate)
> 
> taskDetailFormSet = TaskDetailFormSet(data=data,
>   tiles=tileList,
>   initial=[{"tile":tile.id}
> for tile in tileList])
> 
> return taskDetailFormSet
> 
> But if I don't use initial - how do I create the initial values for
> the forms?  I thought using initial is the "right" way to do it?

I mentioned before that initial data doesn't necessarily make sense for
new models in a modelformset, in some ways (in other ways it does -- but
it's not really practical to handle every single possibility, so
sometimes you just have to deal with it). The thing is that initial data
always results in a populated form -- so data is submitted and a new
entry will be created. That doesn't work for "extra" forms, in the
formset sense, where you're only going to enter new data and, if you
don't, they won't have any effect on things.

If you really, really want to prepopulate fields and can also have some
way to work out whether the data is "new" or the "initial" stuff, then
you'll be able to use it, but you'll have to do some of the form
handling yourself. Reading the source and thinking very hard about
things is the solution to that problem. I'm sure it's possible, but it
will take some thinking. At some point, you just have to say it's not a
standard modelformset case and let go of that particular aid.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: ModelAdmin get_urls w/ invalid literal for int() with base 10

2009-03-04 Thread Brian Neal

On Mar 4, 10:06 pm, Brian Neal  wrote:
> On Mar 4, 9:11 pm, Brian Neal  wrote:
>
>
>
> > I'd like to make my own custom view. In the past I did this by
> > following the django book and added a URL to my main urlpatterns above
> > the '^admin/(.*)' pattern. But I noticed a new get_urls function on
> > the ModelAdmin class in the docs. I'm on trunk, and just did an svn
> > update to 9975 to try this out.
>
> > The docs for get_urls show the view being registered as self.view. Is
> > that possible to register a class method as a view?
>
> > Anyway, just to try things out, I created a view function right in my
> > admin.py file, and my admin.py file looks like this:
>
> >http://dpaste.com/6643/
>
> > I'm kind of guessing here about the URL I need to visit to trigger
> > this new view. My model lives at admin/gcalendar/event, so I'm
> > guessing I need to visit admin/gcalendar/event/my_view. When I do
> > that, I get this error:
>
> > ValueError at /admin/gcalendar/event/my_view/
>
> > invalid literal for int() with base 10: 'my_view'
>
> > With this traceback:  http://dpaste.com/6649/
>
> > For reference, here is my models.py:  http://dpaste.com/6650/
>
> > Thanks!
>
> I put an assert in my get_urls() function and it was not getting hit.
> I made sure that my Django contrib/admin/options.py file does indeed
> have the get_urls() function.
> I deleted all the *.pyc files under site-packages/django and redid the
> 'sudo python setup.py install' step.
> Still no go. I think it is just trying the last default pattern in the
> base ModelAdmin get_urls() and choking on that.

Maybe this ticket is related to what I am seeing?

http://code.djangoproject.com/ticket/10061#comment:4
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



  1   2   >