Re: Blocking multiple form submissions from the same IP address

2009-04-27 Thread Rex



On Apr 26, 6:58 pm, Will Hardy  wrote:
> I would allow the multiple submissions, but make a note of any IP
> addresses to let you exclude the data in the analysis stage.  From
> memory the following "meta" variables might be relevant:
> HTTP_CLIENT_IP, REMOTE_ADDR, HTTP_X_FORWARDED_FOR comma separated)
>
> Although I don't know who your users are, people behind a firewall
> will have the same IP, so will people who switch browsers or close
> cookie-cleaning browsers to complete the survey at another time. Plus
> by doing it this way, you may be able to stop the more determined
> participants, who would try methods you wouldn't be able to detect if
> they knew that their data weren't being accepted.
>
> If this is a more scientific survey, doing it this way helps you show
> that the data are valid (you can say in your report that X
> participants had the same IP address and have therefore been
> excluded).
>
> Cheers,
>
> Will

Thanks Will and Malcolm for the answers. That is just what I was
looking for. It works great.

Best,

Rex
--~--~-~--~~~---~--~~
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: auth.contrib silently catching TypeError. Bug?

2009-04-27 Thread Tamas Szabo

On Tue, Apr 28, 2009 at 12:31 PM, James Bennett  wrote:
>
> On Mon, Apr 27, 2009 at 10:49 PM, Tamas Szabo  wrote:
>> I'm new to Python so I might not understand how keyword arguments work, BUT
>> you do assume that authenticate will always be called with keyword
>> arguments which isn't true.
>
> If you look at how django.contrib.auth.authenticate is implemented,
> you'll see that it will *always* invoke the backend's authenticate()
> keyword-style, which means an invalid argument set will *always* raise
> TypeError.

OK, I missed that bit, sorry for that.
You are right, the second issue isn't really an issue then.

I still don't like that TypeError is silenced, but I will get used to
it I guess :).

Regards,

Tamas

--~--~-~--~~~---~--~~
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: Template within a Template

2009-04-27 Thread Marcelo Ramos

On Mon, Apr 27, 2009 at 9:12 PM, Renato Untalan  wrote:
>
> Hey guys,
>
> In my current project, I'm making a soap call to a remote server,
> which will return to me a Django template.
> Once I have the Django template, I insert it into my Context object,
> and when it renders, it renders the template in plain text, and does
> not show any of the HTML tags.
>
> My context object's dictionary:
> myVars = { "custom_settings_template" : connector_template }
>
> My template:
>
> 
> {{ connector_template }}

I think you need the "safe" template filter there [1]:

{{ connector_template|safe }}

Beware of the html you are injecting from the soap call, the safe
filter will let it pass unmodified. Maybe you can chain "safe" with
the filter "removetags" [2] to get rid of potentially dangerous html
tags.

[1] http://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe
[2] http://docs.djangoproject.com/en/dev/ref/templates/builtins/#removetags

Regards.

-- 
Marcelo Ramos
Django/Python developer

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



MultipleHiddenInput() causes has_changed() to always be true?

2009-04-27 Thread Margie

In one of my forms I've declared a MultipleHiddenInput(), like this:

self.fields['tiles'].widget = forms.MultipleHiddenInput()

In my model, tiles is a manyToMany field.  When I get the POST from
this form, I find that the has_changed() function returns true for the
form due to this 'tiles' field, even though it hasn't changed.  When I
look at the code, in forms.py I see this:

if not field.show_hidden_initial:
initial_value = self.initial.get(name,
field.initial)
else:
initial_prefixed_name = self.add_initial_prefix
(name)
hidden_widget = field.hidden_widget()
initial_value = hidden_widget.value_from_datadict(
self.data, self.files, initial_prefixed_name)
if field.widget._has_changed(initial_value,
data_value):
self._changed_data.append(name)


and I find I am falling into the if.  Then when the if in the second
to last line executes:

if field.widget._has_changed(initial_value,
data_value):

I find that the values are set like this:

(Pdb) initial_value
[1]
(Pdb) data_value
[u'1']

but has_changed() now returns True.

Malcolm or anyone ... do you have any pointers for me?  The reason I
am sending this data out in the first place as hidden data is that I'm
using formsets and in order to be able to leverage the utility of
formset->save() to save out my objects, it seems necessary to have the
required data in the form.  Thus, I send it out with the form and then
get it back in the POST, which allows me to save the formset to the
underlying object.

This was all working fine when I displayed the fields to the user.
But now that I am trying to hide this ManyToMany field via a
hiddeninput, I find that the form is comign back as "changed" when it
didn't otherwise.

Anyway, haven't had time to fully debug this but am wondering if
anyone has any pointers for me on what this show_hidden_initial
attribute is, if it is relevant here, and if it should be set to 1 in
my case?

Margie


--~--~-~--~~~---~--~~
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: auth.contrib silently catching TypeError. Bug?

2009-04-27 Thread James Bennett

On Mon, Apr 27, 2009 at 10:49 PM, Tamas Szabo  wrote:
> I'm new to Python so I might not understand how keyword arguments work, BUT
> you do assume that authenticate will always be called with keyword
> arguments which isn't true.

If you look at how django.contrib.auth.authenticate is implemented,
you'll see that it will *always* invoke the backend's authenticate()
keyword-style, which means an invalid argument set will *always* raise
TypeError.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: auth.contrib silently catching TypeError. Bug?

2009-04-27 Thread Tamas Szabo

Hi Carl,

On Mon, Apr 27, 2009 at 10:14 PM, Carl Meyer  wrote:
>
> Hi Tamas,
>
> On Apr 23, 3:25 am, Tamas Szabo  wrote:
>> For example if I have a Token based authenticator
>> (authenticate(token)) that is configured to be after my User/Password
>> based authenticator (authenticate(user, password)) in settings.py the
>> current code will call the user/password based authenticator and it
>> will pass in the token as a username (password will be null). If I
>> have an authenticator with 2 string arguments, the same will happen.
>
> I don't think you're understanding how keyword arguments work in
> Python.  Python automatically raises a TypeError if the wrong keyword
> arguments are passed to a function; based on argument name, not type.
> So if "username" and "password" are passed to authenticate(), your
> hypothetical "authenticator with 2 string arguments" will still raise
> a TypeError unless its two arguments are actually named "username" and
> "password" - in which case they should be exactly what you're
> expecting.  And if only "token" is passed to authenticate(), calling
> the standard auth backend will raise TypeError, it won't "pass in the
> token as username" at all.

I'm new to Python so I might not understand how keyword arguments work, BUT
you do assume that authenticate will always be called with keyword
arguments which isn't true.

Python will happily invoke authenticate if you called it like:

authenticate("some token")

or

authenticate(token, domain)

or

authenticate(1, 2)

etc.

Anyway, the bug has been closed in the mean time authenticate(...)
will stay as it is.
That's fine with me, as I said before, I just made an observation on
how the implementation could be improved (in my opinion that is)
whether some action would be taken on it it's not for me to decide.


Regards,

Tamas

--~--~-~--~~~---~--~~
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: Strange inconsistency between SQL and ORM with SQLite.

2009-04-27 Thread Tai Lee

I've tested with `django.db.connection` and `pysqlite2` in python and
the sqlite3 prompt, all work as expected. Only using `extra()` with
both `select` and `select_params` doesn't work.

I've opened up a ticket [1] for this. After discussion with Alex
Gaynor on IRC, it looks like the problem is that Django cannot accept
a string of comma separated values OR an iterator as a param to `extra
()` as it will not be properly escaped. Hopefully this can be fixed as
a feature enhancement, or the documentation changed to make this
limitation clear.

[1] http://code.djangoproject.com/ticket/10942

Cheers.
Tai.

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



Template within a Template

2009-04-27 Thread Renato Untalan

Hey guys,

In my current project, I'm making a soap call to a remote server,
which will return to me a Django template.
Once I have the Django template, I insert it into my Context object,
and when it renders, it renders the template in plain text, and does
not show any of the HTML tags.

My context object's dictionary:
myVars = { "custom_settings_template" : connector_template }

My template:


{{ connector_template }}


Is there a better way to do this?  The service lets users generate
their own custom Django templates.


Any clues, tips, hints, or ideas would be very appreciated!


--~--~-~--~~~---~--~~
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: automatic updates for a set of model objects via email

2009-04-27 Thread Timboy

Reading back through I might still not have explained simply enough.

I have a VehicleSearch Model with a m2m to Vehicle and a FK to User. I
want to be able to notify the user that has the VehicleSearch object
when a vehicle inside of the m2m has been added or updated.

I'm looking for the best way to cross reference the new ones and the
best way to handle the notifications that the specific VehicleSearch
was updated with N new vehicles and there were changes to N vehicles.

TIA

On Apr 23, 10:42 pm, Timboy  wrote:
> Let me be more specific to my needs:
>
> Here is my example AutoSearch model:
> name = charfield
> uuid = uuid
> query = charfield
> autos = m2m
> updated = boolean
> emailed_on_update = boolean
> emailed_on_new = boolean
>
> Here are my needs:
>  * updates to this search send the user an email
>  * the user needs to know which autos were updated
>  * new autos email the user
>  * the user needs to know which autos are new
>
> Questions assuming 1000 users.
>
>  * Should this be a cron?
>  * should I add two more m2m's to autos 1 for new autos and 1 for
> updated autos? or is there a better way to keep track for the user?
>
> Thanks.
>
> On Apr 23, 10:20 pm, Alex Gaynor  wrote:
>
> > On Fri, Apr 24, 2009 at 1:15 AM, Timboy  wrote:
>
> > > I want my users to be able to be updated for changes to specific
> > > models objects.
>
> > > Let's say a user does a search of vehicle listings and the search
> > > returns 3 cars. I want them to be able to be alerted when any of those
> > > three car listings get updated. What's the best way to accomplish
> > > this?
>
> > > TIA
>
> > The first thing to figure out is will this feature be for any model or for a
> > specific one?  The next step is to set up a DB table, it's probably going to
> > just be a few columns, a foreign key to user(or maybe just an email field if
> > you want unauthenticated users to be able to sign up for updates), and a
> > foreign key to the model(or a generic foriegn key).  Then you'd write a
> > signal handler, probably a post_save one, that sends out an email to the
> > appropriate people if it determines that the object has been changed, and it
> > would just send emails to everyone who's email is in the table.
>
> > 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: When updating a model instance, list changed fields from inside save()?

2009-04-27 Thread JK Laiho

> In your save method, if self has a value for 'id' we know it already
> exists in the database. We can therefore use that id to get another
> instance with that ID, fresh from the database. This will have the
> *old* values. We can therefore iterate through the attributes of both
> the new and old instances - maybe using x.__dict__.items() - and
> compare them.

Comparing the instance whose save() method I'm in with another, still
intact pre-update instance was something I actually considered doing,
but I thought it was a bit "brute-forcey", not the hypothetical
elegant solution, which would only involve the changed instance
itself, I guess.

I was hoping that an instance would have some way of accessing the in-
database values of its fields, bypassing the changed fields in their
pre-updated state, but I wasn't aware of the fundamental disconnect
that you described here:

> The key thing to understand here is that a Django model instance is
> just a *representation* of an item from the database, it isn't
> actually linked to it at all except when you load and save.

So, thank you for the clarification.

But, having read your response, I thought of another way to (maybe) do
it, one that doesn't involve retrieving another instance for an
iterative field-by-field check.

What I'm considering is a way to override the instance attribute
change operation (sm_bar.name = "Just some random model") so that
before the change actually takes place, a custom hook saves the old
value of the name field into a custom dictionary inside the instance.
When the model instance gets saved later on, the save() method checks
what keys (representing the names of changed fields) are present in
that custom dictionary and constructs the change log entry based on
that. No iterating comparisons through the fields of two separate
instances would be required.

Problem is, I don't know how to do that ;-). The overriding process
sounds a lot like something that could be done with Python descriptors
(__set__, specifically), but I have zero experience with them.

Would this be a feasible approach?

Thanks again,
JK Laiho
--~--~-~--~~~---~--~~
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: FileField error

2009-04-27 Thread Andrew Smith
It depends if you are running under the dev server or not. If you are then
yes, you need to add that path to your urls to serve as static files. I fyou
are running under apache then you should be letting apache handle serving
static files. Have a look at the documentation on apache deployment to see
how.

Thanks

Andy

2009/4/27 Jesse 

>
> I am receiving this error when requesting a pdf file that was uploaded
> in admin using FileField
>
> Page not found (404)
> Request Method: GET
> Request URL:http://127.0.0.1:8000/site_media/pdf/Alg_.pdf
>
> The settings file:
> MEDIA_URL = 'http://127.0.0.1:8000/site_media/'
>
>
> the models file:
>  internalfilename = models.FileField(upload_to="pdf/", blank=True,
> help_text="Publication must NOT be copyrighted")
>
> Postgres table:
> internalfilename  character length 100
>
> Template:
>
> {% if publication.internalfilename %}
> ( {{ publication.mediaformat.mediaformat|safe }}
> {{ publication.digitalsize|safe }})
>   {% else %}
>
>   {% endif %}
>
> Shouldn't the pdf file open without having to add anything to the
> URL.py file?
>
> Thank you for any help
>
> >
>

--~--~-~--~~~---~--~~
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: ignore urls

2009-04-27 Thread David Keegan
It turned out to be a problem with how I was formating my wordpress urls.
Sorry for the post, thanks for the help! I'm sure LocationMatch will be
helpful soon :)

On Mon, Apr 27, 2009 at 12:38 PM, Malcolm Tredinnick <
malc...@pointy-stick.com> wrote:

>
> On Mon, 2009-04-27 at 12:25 -0700, keegan3d wrote:
> > I'm having trouble getting django to ignore my blog urls.
> >
> > I run wordpress from /blog, and django from /. /blog is working, but
> > if I try to navigate to anything deeper django takes over.
> >
> > http://inscopeapps.com/blog/ - works
> > http://inscopeapps.com/blog/wp-django/ - does not work
> >
> > I set this in the apache conf but it didn't work:
> > 
> > SetHandler None
> > 
>
> This isn't really a Django related question. It's about how to configure
> Apache.
>
> Have a look at the documentation for the Location directive in the
> Apache manual. Also have a look at LocationMatch. They're different and,
> in particular, Location is a much more specific match and doesn't
> extrapolate to treating the URL you've specified as the root of a
> sub-tree.
>
> Regards,
> Malcolm
>
>
>
> >
>


-- 
David Keegan
http://inscopeapps.com
http://keegan3d.tumblr.com
http://twitter.com/keegan3d
http://dewdcast.com

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



Re: Django beta slower with some queries?

2009-04-27 Thread Malcolm Tredinnick

On Mon, 2009-04-27 at 13:11 -0700, julianb wrote:
[...]
> In my code, I just used a queryset as parameter for __in and in
> previous Django versions it would evaluate to a list of numbers
> whereas now it does a subselect. I don't think that's very backwards
> compatible.

It's fully backwards compatible. Exactly the same results are returned;
the functionality is identical.

Further, on most database servers we support, the subselect approach
will be faster, since network roundtrips, C to Python conversions and
some data marhsalling operations are all avoided. It also gives the
database server as more opportunities to perform optimisations. You
mentioned you were using MySQL as the backend, which, sadly, has some
performance issues with (some) subselects and you will have to check the
various things you're doing there, hence the documentation note. It's
not correct to always avoid subselects with MySQL (which is why we
don't), but has to be examined case-by-case if the query is
time-critical. Hopefully that will work improve in the future, as the
MySQL developers enable the server and storage engine optimisation paths
to interact a bit more. Some of that work is happening already as part
of the Drizzle project.

> Reading the part "Performance considerations" got me in the right
> direction but didn't help me very well, because if you do it like
> that, it will still do a subselect. 

That's a documentation bug. There should be a list() call wrapped around
the rhs of the first line in the fragment in "Performance
considerations". If you open a ticket for that, we'll fix it.

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: Google Appengine patch and Apengine Helper

2009-04-27 Thread Waldemar Kornewald

Hi,

On Apr 27, 5:12 pm, Lakshman Prasad  wrote:
> I managed to successfully use the second app (appengine-patch). Thanks.
>
> > but there has not been any visible activity
> > on 1)app-engine Django since about August 08
>
> Altho' there hasn't been a release, there has been continuous (weekly)
> activity even in the earlier helper 
> project.http://code.google.com/p/google-app-engine-django/source/list

Just if you're still wondering which project to use:
app-engine-patch contains everything that app-engine-django has (it
was once based on app-engine-django) and a lot more. For example, app-
engine-patch supports the Django admin interface (the helper does
not). Also, you probably don't want to our media generator. Just take
a deeper look our website. It even contains a small comparison at the
bottom (yeah, I've quickly improved it a little bit :):
http://code.google.com/p/app-engine-patch/

> I am definitely looking forward to the day when django works on appengine
> out of the box. Is that feasible? Can there be a generic mapper from ORM to
> Bigtable?

This is planned for a future release of app-engine-patch (we'll
probably change the project name, though). I've started documenting a
high-level plan here:
http://code.djangoproject.com/wiki/AppEngine
The first step will probably not be an official port, though. We might
begin by directly patching the Django source code instead of writing a
backend solution. After that step we might actually work on a clean
integration into the Django repo. Obviously, this will take a lot of
time, so I can't even tell when we'll begin. This also depends on the
number of volunteers that want to help us.

Bye,
Waldemar Kornewald
--~--~-~--~~~---~--~~
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 beta slower with some queries?

2009-04-27 Thread julianb

On Apr 24, 6:05 pm, Karen Tracey  wrote:
> I'd start by using a couple of Python shells (one using 1.0.2 and one using
> 1.1 beta) and connection.queries to see if you can see the difference in SQL
> generated for whatever model queries your view is using:
>
> http://docs.djangoproject.com/en/dev/faq/models/
>
> Karen

Hi Karen,

I wouldn't have written the post if I had not already done that. At
least so I thought. Comparing the resulting queries once more, I found
the difference. Django is using subselects now.
http://docs.djangoproject.com/en/dev/ref/models/querysets/#in

In my code, I just used a queryset as parameter for __in and in
previous Django versions it would evaluate to a list of numbers
whereas now it does a subselect. I don't think that's very backwards
compatible.

Reading the part "Performance considerations" got me in the right
direction but didn't help me very well, because if you do it like
that, it will still do a subselect. I had to explicitly rewrite the
ValuesListQuerySet to a list to really get a list of IDs into my
query. Looks like a bug, but I'm too busy to confirm that right now.

Julian
--~--~-~--~~~---~--~~
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: Replacing the standard User class with a custom one

2009-04-27 Thread Emmanuel Surleau

On Monday 27 April 2009 21:17:44 Malcolm Tredinnick wrote:
> On Mon, 2009-04-27 at 21:11 +0200, Emmanuel Surleau wrote:
> > On Monday 27 April 2009 20:12:13 karl wrote:
> > > > Apologies in advance, I'm sure this query pops up regularly.
> > > >
> > > > I'd like to replace the default User class which comes with Django's
> > > > authentication system (for my application, users login via
> > > > email/password, not login/password, so it's not only a matter of
> > > > adding fields).
> > > >
> > > > Is there an easy way to do it? Or should I just roll my own and give
> > > > on the default authentication system and (sniff) admin site?
> > >
> > > This blog article explains it simply and has ready-to-use code:
> > >
> > > http://www.davidcramer.net/code/224/logging-in-with-email-addresses-
in-
> >
> > djan
> >
> > >go.html
> >
> > Very nice and useful. However, it suffers from a simple flaw: the default
> > Django user model does not guarantee the uniqueness of email 
addresses,
> > which is a problem when you need it as primary key.
>
> Non-uniqueness is a consideration, but your conclusion doesn't follow.
> You don't need it as a primary key for what you're doing. and creating a
> new model won't solve the bulk of the problem. You do want to check that
> the email address is unique and that's a matter of doing so at form
> creation time. Django doesn't currently have any level of model-field
> validation, so this has to be checked in the form in any case (or in the
> code that is creating the user).

I'm aware of this. I'm more concerned about data integrity.

> You can certainly do an "alter table" on your database to add the
> uniqueness constraint to the column if you want to make sure no
> non-unique entries are inserted. That doesn't require a model change. If
> you're creating a form to enable users to specify their details,
> manually specify that the email (form) field should have unique=True. If
> you're doing it via code (e.g. calling User.objects.create_user()),
> check for uniqueness first -- creating a new or different model won't
> help you there in any case, so it's not creating any extra work.

The advantage of having the uniqueness specified in the model is that you 
get it "for free" with syncdb. At the same time, I'm migrating from another 
framework (and DBMS), so I'll get to write SQL to port the data to Django 
anyway.

So maybe you're right and I'm worrying too much about details.

Thanks,

Emm

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



Test client - session data is empty and won't save new entries

2009-04-27 Thread Stefan Wallner

Hi,
I am writing some tests for an application I am developing, in my test
case's setUp I do

self.dummy1 = User.objects.create_user('dummy1', 'n...@example.com',
self.c = Client()
self.c.login(username='dummy', password='dummy')

In one of the tests I POST some data and then check that the
response.status_code I get is a 302 followed by a GET to the page the
browser would get redirected to (since 1.0 doesn't automatically
follow a redirect).

In a browser the response on this redirected-to page contains some
session data which is rendered on the page. In my test however the
session does not contain this information, which I also verified by
dropping into pdb after the GET:

-> self.assertEquals(response.status_code, 200)
(Pdb) self.c

(Pdb) self.c.session

(Pdb) self.c.session.keys()
['_auth_user_id', '_auth_user_backend']
(Pdb) self.c.session['test'] = 'hello'
(Pdb) self.c.session

(Pdb) self.c.session['test']
*** KeyError: 'test'
(Pdb) self.c.session.save()
(Pdb) self.c.session

(Pdb) self.c.session.keys()
['_auth_user_backend', '_auth_user_id']
(Pdb)


In my settings.py the (what I think) are the relevant entries:
...

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'djangologging.middleware.LoggingMiddleware',
)

...

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.flatpages',
'django.contrib.sessions',
'django.contrib.sites',
...
)

...

CACHE_BACKEND = 'file:///var/tmp/django_cache'
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
SESSION_FILE_PATH = '/var/tmp'
...

This is on Django 1.0. (haven't gotten around to upgrade to 1.0.2 yet,
but at least the release notes wouldn't indicate any problems in this
direction.)

I am sure I am missing something obvious, but haven't been able to
figure it out for two days now - help!

Thanks
Stefan
--~--~-~--~~~---~--~~
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: ignore urls

2009-04-27 Thread Malcolm Tredinnick

On Mon, 2009-04-27 at 12:25 -0700, keegan3d wrote:
> I'm having trouble getting django to ignore my blog urls.
> 
> I run wordpress from /blog, and django from /. /blog is working, but
> if I try to navigate to anything deeper django takes over.
> 
> http://inscopeapps.com/blog/ - works
> http://inscopeapps.com/blog/wp-django/ - does not work
> 
> I set this in the apache conf but it didn't work:
> 
> SetHandler None
> 

This isn't really a Django related question. It's about how to configure
Apache.

Have a look at the documentation for the Location directive in the
Apache manual. Also have a look at LocationMatch. They're different and,
in particular, Location is a much more specific match and doesn't
extrapolate to treating the URL you've specified as the root of a
sub-tree.

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



ignore urls

2009-04-27 Thread keegan3d

I'm having trouble getting django to ignore my blog urls.

I run wordpress from /blog, and django from /. /blog is working, but
if I try to navigate to anything deeper django takes over.

http://inscopeapps.com/blog/ - works
http://inscopeapps.com/blog/wp-django/ - does not work

I set this in the apache conf but it didn't work:

SetHandler None

--~--~-~--~~~---~--~~
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: Replacing the standard User class with a custom one

2009-04-27 Thread Malcolm Tredinnick

On Mon, 2009-04-27 at 21:11 +0200, Emmanuel Surleau wrote:
> On Monday 27 April 2009 20:12:13 karl wrote:
> > > Apologies in advance, I'm sure this query pops up regularly.
> > >
> > > I'd like to replace the default User class which comes with Django's
> > > authentication system (for my application, users login via
> > > email/password, not login/password, so it's not only a matter of adding
> > > fields).
> > >
> > > Is there an easy way to do it? Or should I just roll my own and give on
> > > the default authentication system and (sniff) admin site?
> >
> > This blog article explains it simply and has ready-to-use code:
> >
> > http://www.davidcramer.net/code/224/logging-in-with-email-addresses-in-
> djan
> >go.html
> 
> Very nice and useful. However, it suffers from a simple flaw: the default 
> Django user model does not guarantee the uniqueness of email addresses, 
> which is a problem when you need it as primary key.

Non-uniqueness is a consideration, but your conclusion doesn't follow.
You don't need it as a primary key for what you're doing. and creating a
new model won't solve the bulk of the problem. You do want to check that
the email address is unique and that's a matter of doing so at form
creation time. Django doesn't currently have any level of model-field
validation, so this has to be checked in the form in any case (or in the
code that is creating the user).

You can certainly do an "alter table" on your database to add the
uniqueness constraint to the column if you want to make sure no
non-unique entries are inserted. That doesn't require a model change. If
you're creating a form to enable users to specify their details,
manually specify that the email (form) field should have unique=True. If
you're doing it via code (e.g. calling User.objects.create_user()),
check for uniqueness first -- creating a new or different model won't
help you there in any case, so it's not creating any extra work.

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: i need a unlimited subcategories

2009-04-27 Thread R. Gorman

Treebeard is another option.

http://code.google.com/p/django-treebeard/

I'm sure between mptt or treebeard, you'll find something suitable.

R.
--~--~-~--~~~---~--~~
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: Replacing the standard User class with a custom one

2009-04-27 Thread Emmanuel Surleau

On Monday 27 April 2009 20:12:13 karl wrote:
> > Apologies in advance, I'm sure this query pops up regularly.
> >
> > I'd like to replace the default User class which comes with Django's
> > authentication system (for my application, users login via
> > email/password, not login/password, so it's not only a matter of adding
> > fields).
> >
> > Is there an easy way to do it? Or should I just roll my own and give on
> > the default authentication system and (sniff) admin site?
>
> This blog article explains it simply and has ready-to-use code:
>
> http://www.davidcramer.net/code/224/logging-in-with-email-addresses-in-
djan
>go.html

Very nice and useful. However, it suffers from a simple flaw: the default 
Django user model does not guarantee the uniqueness of email addresses, 
which is a problem when you need it as primary key.

Sorry for not having made this point more clearly, but this is why I was 
talking about replacing Django's default model. Do you know if there is a way 
around this?

Cheers,

Emm

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



FileField error

2009-04-27 Thread Jesse

I am receiving this error when requesting a pdf file that was uploaded
in admin using FileField

Page not found (404)
Request Method: GET
Request URL:http://127.0.0.1:8000/site_media/pdf/Alg_.pdf

The settings file:
MEDIA_URL = 'http://127.0.0.1:8000/site_media/'


the models file:
 internalfilename = models.FileField(upload_to="pdf/", blank=True,
help_text="Publication must NOT be copyrighted")

Postgres table:
internalfilename  character length 100

Template:

 {% if publication.internalfilename %}
 ( {{ publication.mediaformat.mediaformat|safe }}
{{ publication.digitalsize|safe }})
   {% else %}

   {% endif %}

Shouldn't the pdf file open without having to add anything to the
URL.py file?

Thank you for any help

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



ForeignKey Select List Filter

2009-04-27 Thread cfiles

I have a model with a ForeignKey to another model. Is it possible to
filter the HTML select list for the foreign object from a view?
--~--~-~--~~~---~--~~
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 local variables in custom exception middleware

2009-04-27 Thread skunkwerk

Hi,
   i've been using django-db-log for logging exceptions when
Debug=False, and I'd like to add the ability to log the local
variables as well.  Here is what I tried:

def process_exception(self, request, exception):

local_vars  = repr(exception.tb_frame.f_locals.items())

however, tb_frame does not seem to be a function of exception or
traceback.

any suggestions?

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: Replacing the standard User class with a custom one

2009-04-27 Thread karl


> Apologies in advance, I'm sure this query pops up regularly.
>
> I'd like to replace the default User class which comes with Django's
> authentication system (for my application, users login via email/password, not
> login/password, so it's not only a matter of adding fields).
>
> Is there an easy way to do it? Or should I just roll my own and give on the
> default authentication system and (sniff) admin site?
>

This blog article explains it simply and has ready-to-use code:

http://www.davidcramer.net/code/224/logging-in-with-email-addresses-in-django.html

Karl


--~--~-~--~~~---~--~~
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 save() method on models to automatically add ManyToMany relationship

2009-04-27 Thread Adam Olsen

On Mon, Apr 27, 2009 at 11:27 AM, Alex Gaynor  wrote:

> The issues if the method, it's nonsensical and doesn't correspond to
> anything(you are instantiating models.Model with save as the first
> argument), in Python the correct way to call the parent class's method is:
>
> super(MyClass, self).save(*args, **kwargs)

It was an example, complete with a typo.  It should have been:

def save(self, *args):
  models.Model.save(self, *args)
  category = Category.objects.all()[0]
  self.categories.add(category)

However, that point is not the problem.  Even with the proper syntax,
it doesn't save the ManyToMany relationship.

-- 
Adam Olsen
SendOutCards.com
http://www.vimtips.org
http://last.fm/user/synic

--~--~-~--~~~---~--~~
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: mysite.polls: __init__() got an unexpected keyword argument 'max_length'

2009-04-27 Thread bconnors

With my ubuntu I can’t type @
So I can’t do :
export PYTHONPATH=/path/to/your/django/checkout
to the directory I was using which was
pubu...@pubuntu:~/djsite/mysite$

so I thought I’d use /usr/share/bob because it has no @
but that doesn’t work either:

+ svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
svn: Working copy 'django-trunk' locked
svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for
details)
r...@pubuntu:/usr/share/bob# svn cleanup
svn: '.' is not a working copy directory

is there any directory without a @
that I can use?


On Apr 27, 12:32 pm, Karen Tracey  wrote:
> On Mon, Apr 27, 2009 at 10:40 AM, bconnors  wrote:
> > [snip stuff related to removing old Django level]
> > I found that my site/packages is in /usr/lib/python2.5/site-packages
> > and in that directory I did
> > pubu...@pubuntu:~/djsite/mysite$ cat dj
> > svn cohttp://code.djangoproject.com/svn/django/trunk/django-trunk
>
> > so in /usr/lib/python2.5/site-packages the django is 10638
>
> > I’m working in pubu...@pubuntu:~/djsite/mysite$ cat dj
> > svn cohttp://code.djangoproject.com/svn/django/trunk/django-trunk
> > Checked out revision 10638.
>
> I cannot understand what you are saying you did here.  You show two checkout
> commands (except you are cat-ing a file that apparently contains the
> checkout command, not actually running the checkout, so far as I can see)
> and say you did one in your site-packages directory but the one that shows
> the "Checked out" message appears to have been issued from ~/djsite/mysite,
> not your Python's site-packages directory.
>
> In fact it isn't recommended that you do an svn checkout directly into
> site-packages.  Step 3 of the documentation here:
>
> http://docs.djangoproject.com/en/dev/topics/install/#installing-devel...
>
> recommends creating a symbolic link in site-packages pointing to wherever
> you put your svn checkout.  Have you tried following those instructions?
>
>
>
> > Why do I get an error when I do:
> > pubu...@pubuntu:~/djsite/mysite$ python manage.py runserver
> > Traceback (most recent call last):
> >  File "manage.py", line 2, in 
> >    from django.core.management import execute_manager
> > ImportError: No module named django.core.management
> > pubu...@pubuntu:~/djsite/mysite$
>
> Whatever you have done has not resulted in there being a 'django' directory
> tree in your Python's site-packages directory.  Possibly you have a
> 'django-trunk' directory tree there, if indeed you did a checkout directly
> into site-packages but as I said above I'm not really sure what you did.
> Following the instructions, exactly, on the page I pointed to above, would
> really be your best bet.
>
> 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: Overriding save() method on models to automatically add ManyToMany relationship

2009-04-27 Thread Alex Gaynor
On Mon, Apr 27, 2009 at 1:24 PM, Adam Olsen  wrote:

>
> I've got two models, something like this:
>
> class Category(models.Model):
>name = models.CharField(max_length=60)
>
> class Product(models.Model):
>sku = models.CharField(max_length=20)
>categories = models.ManyToManyField(Category)
>
> I want to overload the save method to automatically add certain
> products to certain categories in special cases:
>
> def save(self, *args):
>   models.Model(save, *args)
>   category = Category.objects.all()[0]
>   self.categories.add(category)
>
> This does not work, I'm sure it's saving ManyToMany relationships
> later on in the save process.  Is there a way to make this work?
>
> --
> Adam Olsen
> SendOutCards.com
> http://www.vimtips.org
> http://last.fm/user/synic
>
> >
>
The issues if the method, it's nonsensical and doesn't correspond to
anything(you are instantiating models.Model with save as the first
argument), in Python the correct way to call the parent class's method is:

super(MyClass, self).save(*args, **kwargs)

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



Overriding save() method on models to automatically add ManyToMany relationship

2009-04-27 Thread Adam Olsen

I've got two models, something like this:

class Category(models.Model):
name = models.CharField(max_length=60)

class Product(models.Model):
sku = models.CharField(max_length=20)
categories = models.ManyToManyField(Category)

I want to overload the save method to automatically add certain
products to certain categories in special cases:

def save(self, *args):
   models.Model(save, *args)
   category = Category.objects.all()[0]
   self.categories.add(category)

This does not work, I'm sure it's saving ManyToMany relationships
later on in the save process.  Is there a way to make this work?

-- 
Adam Olsen
SendOutCards.com
http://www.vimtips.org
http://last.fm/user/synic

--~--~-~--~~~---~--~~
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: mysite.polls: __init__() got an unexpected keyword argument 'max_length'

2009-04-27 Thread Karen Tracey
On Mon, Apr 27, 2009 at 10:40 AM, bconnors  wrote:

> [snip stuff related to removing old Django level]
> I found that my site/packages is in /usr/lib/python2.5/site-packages
> and in that directory I did
> pubu...@pubuntu:~/djsite/mysite$ cat dj
> svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
>
> so in /usr/lib/python2.5/site-packages the django is 10638
>
> I’m working in pubu...@pubuntu:~/djsite/mysite$ cat dj
> svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
> Checked out revision 10638.
>

I cannot understand what you are saying you did here.  You show two checkout
commands (except you are cat-ing a file that apparently contains the
checkout command, not actually running the checkout, so far as I can see)
and say you did one in your site-packages directory but the one that shows
the "Checked out" message appears to have been issued from ~/djsite/mysite,
not your Python's site-packages directory.

In fact it isn't recommended that you do an svn checkout directly into
site-packages.  Step 3 of the documentation here:

http://docs.djangoproject.com/en/dev/topics/install/#installing-development-version

recommends creating a symbolic link in site-packages pointing to wherever
you put your svn checkout.  Have you tried following those instructions?


>
> Why do I get an error when I do:
> pubu...@pubuntu:~/djsite/mysite$ python manage.py runserver
> Traceback (most recent call last):
>  File "manage.py", line 2, in 
>from django.core.management import execute_manager
> ImportError: No module named django.core.management
> pubu...@pubuntu:~/djsite/mysite$
>

Whatever you have done has not resulted in there being a 'django' directory
tree in your Python's site-packages directory.  Possibly you have a
'django-trunk' directory tree there, if indeed you did a checkout directly
into site-packages but as I said above I'm not really sure what you did.
Following the instructions, exactly, on the page I pointed to above, would
really be your best bet.

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: Is there a bug in queryset distinct() filtration in Postgre SQL?

2009-04-27 Thread NoviceSortOf

Thanks Malcom...

Simply adding values() to the query with author and title to the
search worked perfectly in limiting the SQL DISTINCT criteria to the
relevant fields,

Using...

results = Titles.objects.values('author','title').filter(qset).order_by
().distinct()

Django provides this elegant and functioning SQL

results.query.as_sql()

('SELECT DISTINCT "books_titles"."author", "books_titles"."title" FROM
"books_titles" WHERE "books_titles"."copyid"::text LIKE %s ',
(u'%842838%',))


--~--~-~--~~~---~--~~
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: Replacing the standard User class with a custom one

2009-04-27 Thread Malcolm Tredinnick

On Mon, 2009-04-27 at 08:09 +0200, Emmanuel Surleau wrote:
> Hello,
> 
> Apologies in advance, I'm sure this query pops up regularly.
> 
> I'd like to replace the default User class which comes with Django's 
> authentication system (for my application, users login via email/password, 
> not 
> login/password, so it's not only a matter of adding fields).

You don't have to change the User model to do that. You only need to
write a different authentication backend.

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 there a bug in queryset distinct() filtration in Postgre SQL?

2009-04-27 Thread Malcolm Tredinnick

On Mon, 2009-04-27 at 08:51 -0700, NoviceSortOf wrote:
> 
> Thanks for the as_sql() function as can now can
> see the SQL detail. Which reveals a problem in
> getting DISTINCT to draw from a fields or fields that can in fact
> return the unique result of the query. Perhaps it is my usage
> of the function so I'm listing an examble
> below.
> 
> To further simplify my example and testing I'm  using an internal
> product number that in this instance refers to all editions of the
> book Moby Dick by Herman Melville.
> 
> qset = (Q(editionid__contains=q_bookid))
> 
> results = Titles.objects.filter(qset).order_by().distinct()
> assert False, resultsa.query.as_sql()
> 
> Here is the SQL it generates results...
> 
> ('SELECT DISTINCT "books_titles"."id", "books_titles"."keywords",
> "books_titles"."editionid", "books_titles"."author",
> "books_titles"."title", "books_titles"."price",
> "books_titles"."bookid" FROM "books_titles" WHERE
> "books_titles"."author"::text LIKE %s ', (u'%842838%',))
> 
> Now with the above if I read correctly the DISTINCT is being placed on
> book_titles.id

That isn't correct. That SQL is saying each set of selected results will
be distinct. The "DISTINCT" modifier is applied to the tuple of output
columns and any tuples that occur more than once have duplicates
discarded from the result set.

[...]

> So for output I get something like...
> 
> EditionId BookID AuthorTitle
> = == = =
> 2001  200Melville  Moby does Captain Bly
> 2002  200Melville  Moby does Captain Bly
> 2004  200Melville  Moby does Captain Bly

Those are all distinct rows. The EditionID value is different in each
set of output columns. There's no error there. I think you're
misunderstanding how distinct works in SQL and Django.

> When in fact all I need for the seeding the
> initial search results is
> 
> EditionId BookID AuthorTitle
> = == = =
> 2001  200Melville  Moby does Captain Bly

How is Django meant to know that it should throw away a whole bunch of
rows and only keep the first EditionId value and not the others? It
can't.

Your original queryset explicitly asked for things matching a particular
set of editionid values ("all the editioid values in this set"). Even I,
as a human, not a computer, would have given you the first set of
results and not the second, since you indicated the different edition id
values were significant. Your expectation isn't particularly intuitive
even in human terms.

If you only care about distinct (BookID, Author, Title) tuples, then use
the values() method on the queryset. The distinct() modifier will be
applied only to those values (plus any ordering), since they're then the
only columns selected.

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 there a bug in queryset distinct() filtration in Postgre SQL?

2009-04-27 Thread NoviceSortOf


Thanks for the as_sql() function as can now can
see the SQL detail. Which reveals a problem in
getting DISTINCT to draw from a fields or fields that can in fact
return the unique result of the query. Perhaps it is my usage
of the function so I'm listing an examble
below.

To further simplify my example and testing I'm  using an internal
product number that in this instance refers to all editions of the
book Moby Dick by Herman Melville.

qset = (Q(editionid__contains=q_bookid))

results = Titles.objects.filter(qset).order_by().distinct()
assert False, resultsa.query.as_sql()

Here is the SQL it generates results...

('SELECT DISTINCT "books_titles"."id", "books_titles"."keywords",
"books_titles"."editionid", "books_titles"."author",
"books_titles"."title", "books_titles"."price",
"books_titles"."bookid" FROM "books_titles" WHERE
"books_titles"."author"::text LIKE %s ', (u'%842838%',))

Now with the above if I read correctly the DISTINCT is being placed on
book_titles.id
which of course will always be unique and
always return every instance, which does not  return a unique list.

So for output I get something like...

EditionId BookID AuthorTitle
= == = =
2001  200Melville  Moby does Captain Bly
2002  200Melville  Moby does Captain Bly
2004  200Melville  Moby does Captain Bly

When in fact all I need for the seeding the
initial search results is

EditionId BookID AuthorTitle
= == = =
2001  200Melville  Moby does Captain Bly

At least now though the SQL is explicit
and I can perhaps dig a bit into the code
to see how it works, but if anyone can offer
any further insights it would be of great
help.

--~--~-~--~~~---~--~~
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: ManyToMany relationship being 'lost'?

2009-04-27 Thread Rubens Altimari

Hey Jorge,

> The relation disappears when (existing a relation) y use this modelForm
> without including any info for the friends field (I don't what to edit this
> information at this point). At this moment, django erases the relation
> within A an B because wasn't explicit declared and the forms validates
> because it can be blank and null.

Thanks for the hint - but that was not the case. I do have custom
ModelForms, and the relationship fields are there, very explicit. So I
suppose they would only get overriden intentionally.

I'm starting to think that my customer sometimes keep more than one
browser/tab open, and inadvertently updates the wrong one, overriding
the other, or something like that...

Regards,
Rubens

--~--~-~--~~~---~--~~
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: Google Appengine patch and Apengine Helper

2009-04-27 Thread Lakshman Prasad
I managed to successfully use the second app (appengine-patch). Thanks.

> but there has not been any visible activity
> on 1)app-engine Django since about August 08

Altho' there hasn't been a release, there has been continuous (weekly)
activity even in the earlier helper project.
http://code.google.com/p/google-app-engine-django/source/list

I am definitely looking forward to the day when django works on appengine
out of the box. Is that feasible? Can there be a generic mapper from ORM to
Bigtable?

The admin console of appengine is awesome. Are there any other webhosts that
provide a similar interface with all that detail?

On Mon, Apr 27, 2009 at 8:05 AM, dartdog  wrote:

>
> Well,, both have issues,, but there has not been any visible activity
> on 1)app-engine Django since about August 08. While the lone developer
> on 2)App engine patch is working hard daily..
>
> I have seen a few posts that others have abandoned # 1 in favor of # 2
> but the projects need more people to contribute!
>
> It appears that the Django community has not found this (app-engine
> support) to be a high priority. you can search for conversations from
> back in Feb that indicate this.
>
> The differing data models are really quite problematic.
>
>
> On Apr 25, 5:56 pm, Lakshman Prasad  wrote:
> > I see 2 different django projects for porting django app to app-engine
> >
> >
> http://code.google.com/p/app-engine-patch/http://code.google.com/p/google-app-engine-django/
> >
> > I'd like to know the preferred module to use and the relative benefits
> and
> > problems.
> >
> > Thanks in advance.
> >
> > --
> > Regards,
> > Lakshman
> > becomingguru.com
> > lakshmanprasad.com
> >
>


-- 
Regards,
Lakshman
becomingguru.com
lakshmanprasad.com

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



Re: mysite.polls: __init__() got an unexpected keyword argument 'max_length'

2009-04-27 Thread bconnors

I did :
apt-get remove python-django

then
pubu...@pubuntu:~/djsite/mysite$ sh -x lk1
pubu...@pubuntu:~/djsite/mysite$ dpkg -l python-django
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-f/Unpacked/Failed-cfg/Half-inst/t-aWait/
T-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err:
uppercase=bad)
||/ Name   VersionDescription
+++-==-==-

rc  python-django  0.96.1-2ubuntu A high-level Python Web framework
pubu...@pubuntu:~/djsite/mysite$

then
pubu...@pubuntu:~/djsite/mysite$ cd /usr/share/python-support/python-
django
-bash: cd: /usr/share/python-support/python-django: No such file or
directory
pubu...@pubuntu:~/djsite/mysite$

so /usr/share/python-support/python-django


As a result of pubu...@pubuntu:~/djsite/mysite$ sh -x w
+ python -c from distutils.sysconfig import get_python_lib; print
get_python_lib
();
/usr/lib/python2.5/site-packages
pubu...@pubuntu:~/djsite/mysite$

I found that my site/packages is in /usr/lib/python2.5/site-packages
and in that directory I did
pubu...@pubuntu:~/djsite/mysite$ cat dj
svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk

so in /usr/lib/python2.5/site-packages the django is 10638

I’m working in pubu...@pubuntu:~/djsite/mysite$ cat dj
svn co http://code.djangoproject.com/svn/django/trunk/ django-trunk
Checked out revision 10638.


Why do I get an error when I do:
pubu...@pubuntu:~/djsite/mysite$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 2, in 
from django.core.management import execute_manager
ImportError: No module named django.core.management
pubu...@pubuntu:~/djsite/mysite$


On Apr 24, 3:22 pm, Karen Tracey  wrote:
> On Fri, Apr 24, 2009 at 1:43 PM, bconnors  wrote:
>
> > i eliminated the field in Poll question = models.CharField
> > (max_length=200) and Choice choice = models.CharField(max_length=200)
> > and the error went away
>
> Sure, but eliminating use of CharFields (plus, as you hit errors, every
> other thing that has changed between 0.96 and 1.0) is not a viable long-term
> strategy.  Really, if you want to make progress, uninstall the 0.96 level
> and install 1.0.2 or set your python path to point to your checkout, or
> "install" your checkout by creating a symbolic link in site-packages.
> Instructions for all of these steps have been given in previous responses in
> this thread.
>
> 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: Getting data post from input with multiple name

2009-04-27 Thread eli

Ok, I'm going to use string (like: items_{{ data.id }})

Thanks.

regards.

On 26 Kwi, 21:31, Malcolm Tredinnick  wrote:
> On Sun, 2009-04-26 at 10:20 -0700, eli wrote:
> > Hi,
>
> > I have problem:
> > In my template, I have some inputs with multiple name like:
> >  > value="{{ data.name }}" />
>
> > How to get this data from request.POST in view method?
>
> > I tried:
> >  - request.POST.get('values', None)
> >  - request.POST.get('values[]', None)
>
> > but didn't wokr..
>
> The name attribute in the HTML form will have a string value for the
> name. You have to use that string value, whatever it might be. If you
> are creating the string value at template rendering time, then you have
> to also compute exactly the same string value when processing the form.
> That is, repeat the logic in your view when accessing request.POST.
>
> There's nothing Django does or can do here. You are specifying the name
> attribute's value, so only you know what it is when it comes time to
> access it in the view.
>
> 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: ManyToMany relationship being 'lost'?

2009-04-27 Thread Jorge Bastida
Hello Rubens,I have similar problems months ago.
In my application there is a ManyToMany relation within two classes (A and
B) let's name the relation as "friends".
The application works fine but in unpredictable situations rows from the
auxiliary table that makes the relation disappears randomly.

I read all the code, an check the "strange" situations one by one.

Finally the problem was that, I use auto generated ModelForms, and in the
exclude rows i didn't include the "friend" field.
As you, the relation has the parameters (blank=True, null=True).

The relation disappears when (existing a relation) y use this modelForm
without including any info for the friends field (I don't what to edit this
information at this point). At this moment, django erases the relation
within A an B because wasn't explicit declared and the forms validates
because it can be blank and null.

The solution? Include "friend" in the exclude list of the model Form.

You are using the default Admin, i was using own forms / templates, but i
suppose internally, django generate forms with modelForms-like classes.

Hope this help you.




-- 
neo2001[at]gmail.com
jorge[at]thecodefarm.com
neo[at]art-xtreme.com

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



Re: auth.contrib silently catching TypeError. Bug?

2009-04-27 Thread Carl Meyer

Hi Tamas,

On Apr 23, 3:25 am, Tamas Szabo  wrote:
> For example if I have a Token based authenticator
> (authenticate(token)) that is configured to be after my User/Password
> based authenticator (authenticate(user, password)) in settings.py the
> current code will call the user/password based authenticator and it
> will pass in the token as a username (password will be null). If I
> have an authenticator with 2 string arguments, the same will happen.

I don't think you're understanding how keyword arguments work in
Python.  Python automatically raises a TypeError if the wrong keyword
arguments are passed to a function; based on argument name, not type.
So if "username" and "password" are passed to authenticate(), your
hypothetical "authenticator with 2 string arguments" will still raise
a TypeError unless its two arguments are actually named "username" and
"password" - in which case they should be exactly what you're
expecting.  And if only "token" is passed to authenticate(), calling
the standard auth backend will raise TypeError, it won't "pass in the
token as username" at all.

Carl
--~--~-~--~~~---~--~~
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: i need a unlimited subcategories

2009-04-27 Thread Paul Nema
Modified Preorder Tree Traversal (mptt)

http://code.google.com/p/django-mptt/

On Mon, Apr 27, 2009 at 9:52 AM, joker  wrote:

>
> how can i use unlimited category?
>
> like
>
> category1
>subcategory1-1
> subcategory1-1-1
> subcategory1-1-2
> subcategory1-1-3
>   subcategory1-1-3-1
>   subcategory1-1-3-2
>subcategory1-2
>
> category2
>subcategory2-1
>subcategory2-2
>
>
> >
>

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



i need a unlimited subcategories

2009-04-27 Thread joker

how can i use unlimited category?

like

category1
subcategory1-1
 subcategory1-1-1
 subcategory1-1-2
 subcategory1-1-3
   subcategory1-1-3-1
   subcategory1-1-3-2
subcategory1-2

category2
subcategory2-1
subcategory2-2


--~--~-~--~~~---~--~~
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: ManyToMany relationship being 'lost'?

2009-04-27 Thread Rubens Altimari

Russ,

Thanks fo the reply!

> The only thought I have is that you appear to be using a pre-existing
> table to manage the m2m relationship, rather than the default produced
> Django table. This shouldn't pose a problem, but it does lead me to
> wonder if there is some other process that could be using that table.

Hmm, not really, maybe I gave this impression when I "simplified" the
name of my models (A and B, etc.), but it's really all Django-created
and managed stuff.

> Other than that - this has all the hallmarks of a user error. Are you
> in a position to 'sit on your client's shoulder' until the problem
> reproduces itself?

Yes, that's what I'm trying to do - of course, being a 'randomic'
error it follows Murphy's laws, and I'm never there when the 'problem'
happens, whatever it is. I'll keep trying, though!

Thanks again,
Rubens

--~--~-~--~~~---~--~~
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: ManyToMany relationship being 'lost'?

2009-04-27 Thread Rubens Altimari

Hi Malcolm,

>> class BidirectionalField(models.ManyToManyField):
>>     def __init__(self, *args, **kwargs):
>>         super(BidirectionalField, self).__init__(*args, **kwargs)
>>         self.creates_table = False

> BY the way, this has been discussed in the past and is really the wrong
> way to skin the cat. It's not a data modelling problem at all, so
> implementing a model field to do this is slightly backwards.

> A sensible approach is to customised the form being displayed and then
> customising saving on that form, etc. This is *purely* a form issue.

Thanks for the tip, I'll look into that and change my approach...

Regards,
Rubens

--~--~-~--~~~---~--~~
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: When updating a model instance, list changed fields from inside save()?

2009-04-27 Thread Daniel Roseman

On Apr 27, 10:08 am, JK Laiho  wrote:
> Something I don't know how to do in an elegant fashion:
>
> Given a model instance that already exists in the database and is
> about to be updated (i.e. some columns of the DB row are changed), is
> there a way for the instance's save() method to see what fields have
> been changed?
>
> I'm writing an app where a custom change log entry must exist for each
> model instance change. Assume this code:
>

>
> For the above scenario, I want to construct a change log message that
> says something like: "name was changed from 'Just some model' to 'Just
> some random model' by [LoggedInUsername]". As the code indicates, this
> would happen inside the save() method of SomeModel.
>
> The thing I can't figure out is this: when the object is retrieved as
> sm_bar and the 'name' field is changed (but before running save()), is
> there any way to "see through" the new 'name' in the instance to
> retrieve the old 'name' still in the database? When entering save(),
> the in-database values could then be rather trivially compared to the
> fresh instance values to construct the change log entry. Of course,
> this would have to work for any model with an arbitrary number of
> fields and an arbitrary number of field changes.
>
> I have a hunch 
> thathttp://docs.djangoproject.com/en/dev/ref/models/instances/#what-happe...
> is the way to a solution, but it's not coming to me right now.
>
> Thanks in advance for any help!


Here's how I'd do this.

In your save method, if self has a value for 'id' we know it already
exists in the database. We can therefore use that id to get another
instance with that ID, fresh from the database. This will have the
*old* values. We can therefore iterate through the attributes of both
the new and old instances - maybe using x.__dict__.items() - and
compare them.

The key thing to understand here is that a Django model instance is
just a *representation* of an item from the database, it isn't
actually linked to it at all except when you load and save. So there's
nothing to stop you going back to the db to get a fresh instance, even
if the one you're already holding has been changed - as long as you
haven't saved in the meantime, the new object will have the values
fresh from the database.

Hope that helps.
--
DR.
--~--~-~--~~~---~--~~
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: Strange inconsistency between SQL and ORM with SQLite.

2009-04-27 Thread Tai Lee

Thanks for your feedback Malcolm. I will try to test without Django
tomorrow.

Since my original post I have noticed that inserting my params
directly into the `select` argument with the string formatting
operator works, but passing them in with the `select_params` argument
causes a failure as described in my original post. The SQL statements
generated are identical.

>>> from django.contrib.auth.models import User
>>> q = User.objects.extra(
... select={'featured': 'auth_user.id IN (%s)'},
... select_params=['1,2']
... ).values('featured', 'pk', 'username').order_by('-featured', 'pk',
'username')

>>> print q.query
SELECT (auth_user.id IN (1,2)) AS "featured", "auth_user"."id",
"auth_user"."username" FROM "auth_user" ORDER BY "featured" DESC,
"auth_user"."id" ASC, "auth_user"."username" ASC

# both of the specified users (1,2) are incorrectly returned with
`featured` as 0.
>>> print list(q)
[{'username': u'admin', 'pk': 1, 'featured': 0}, {'username':
u'manager', 'pk': 2, 'featured': 0}]

>>> q = User.objects.extra(
... select={'featured': 'auth_user.id IN (%s)' % '1,2'}
... ).values('featured', 'pk', 'username').order_by('-featured', 'pk',
'username')

>>> print q.query
SELECT (auth_user.id IN (1,2)) AS "featured", "auth_user"."id",
"auth_user"."username" FROM "auth_user" ORDER BY "featured" DESC,
"auth_user"."id" ASC, "auth_user"."username" ASC

# both of the specified users (1,2) are correctly returned with
`featured` as 1.
>>> print list(q)
[{'username': u'admin', 'pk': 1, 'featured': 1}, {'username':
u'manager', 'pk': 2, 'featured': 1}]



On Apr 26, 4:37 am, Malcolm Tredinnick 
wrote:
> On Thu, 2009-04-16 at 23:11 -0700, Tai Lee wrote:
> > I'm trying to add an extra selection to a queryset, `featured`, which
> > should be True (or 1) if the primary key matches a number of known
> > values.
>
> > It appears to work as expected both in SQL and the ORM when matching
> > against a single value. When I try matching against multiple values, I
> > get the expected results in SQL (`featured` is set to `1` for matching
> > rows), but in the ORM all rows set `featured` to 0.
>
> > I've used the User model in an example, below. There's also a pretty
> > version athttp://dpaste.com/hold/34599/
>
> > # interactive shell.
>
> > >>> from django.contrib.auth.models import User
>
> > # the specified user (1) is returned with `featured` as 1.
>
> > >>> q = User.objects.extra(
> > ...     select={'featured': 'auth_user.id IN (%s)'},
> > ...     select_params=['1']
> > ... ).values('featured', 'pk', 'username').order_by('-featured', 'pk',
> > 'username')
> > >>> print q.query
> > SELECT (auth_user.id IN (1)) AS "featured", "auth_user"."id",
> > "auth_user"."username" FROM "auth_user" ORDER BY "featured" DESC,
> > "auth_user"."id" ASC, "auth_user"."username" ASC
> > >>> print list(q)
> > [{'username': u'admin', 'pk': 1, 'featured': 1}, {'username':
> > u'manager', 'pk': 2, 'featured': 0}]
>
> > # both of the specified users (1,2) are both incorrectly returned with
> > `featured` as 0.
>
> > >>> q = User.objects.extra(
> > ...     select={'featured': 'auth_user.id IN (%s)'},
> > ...     select_params=['1,2']
> > ... ).values('featured', 'pk', 'username').order_by('-featured', 'pk',
> > 'username')
> > >>> print q.query
> > SELECT (auth_user.id IN (1,2)) AS "featured", "auth_user"."id",
> > "auth_user"."username" FROM "auth_user" ORDER BY "featured" DESC,
> > "auth_user"."id" ASC, "auth_user"."username" ASC
> > >>> print list(q)
> > [{'username': u'admin', 'pk': 1, 'featured': 0}, {'username':
> > u'manager', 'pk': 2, 'featured': 0}]
>
> > # the sql statements generated for both querysets are valid and work
> > as expected when executed from the sqlite shell directly.
>
> > sqlite> SELECT (auth_user.id IN (1)) AS "featured", "auth_user"."id",
> > "auth_user"."username" FROM "auth_user" ORDER BY "featured" DESC,
> > "auth_user"."id" ASC, "auth_user"."username" ASC
> > 1|1|admin
> > 0|2|manager
>
> > sqlite> SELECT (auth_user.id IN (1,2)) AS "featured",
> > "auth_user"."id", "auth_user"."username" FROM "auth_user" ORDER BY
> > "featured" DESC, "auth_user"."id" ASC, "auth_user"."username" ASC
> > 1|1|admin
> > 1|2|manager
> > sqlite>
>
> The more relevant test here is what happens when you remove only Django
> from the equation and use pysqlite or the sqlite Python module to do the
> query. It could be something happening at that level. Off the top of my
> head, I can't think of anything Django's doing here that would be
> changing things.
>
> Realise, too, that pysqlite/sqlite module version, sqlite binary version
> and Django version are all likely to be relevant variables here
> (although less so for the Django version). SQLite changes fairly rapidly
> in terms of fixing bugs and its weak-typing behaviour does lead to
> strange things like this from time to time.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are 

Re: Disabling PRG Pattern

2009-04-27 Thread Chris Spencer

On Sun, Apr 26, 2009 at 11:26 PM, Malcolm Tredinnick
 wrote:
>
> On Sun, 2009-04-26 at 19:41 -0700, Chris wrote:
>> On Apr 26, 7:40 pm, Alex Gaynor  wrote:
>> > On Sun, Apr 26, 2009 at 7:39 PM, Chris  wrote:
>> >
>> > > I've noticed a Redirect/Get is issued automatically after every Post
>> > > made. Is there any way to disable this feature? I can't find anything
>> > > in the docs about this.
>> >
>> > > Regards,
>> > > Chris
>> >
>> > Where are you talking about?  No where does django impose upon you a
>> > post-redirect-get pattern for your own views, it just happens to be the
>> > convention.
>>
>> My view returns a normal HTML response by default, and a JSON response
>> for Ajax requests. So it looks like:
>>
>> if request.is_ajax():
>> return JSONResponse({'response_value': 123})
>> else:
>> response = render_to_response('my_page.html',
>>   locals(),
>>   context_instance=RequestContext
>> (request),
>> )
>> response.set_cookie('my_cookie', 123)
>> return response
>>
>> And for either method, if it's a form post, I get a 302 redirect, and
>> I really have no idea why. It's driving me nuts.
>
> There's nothing in that code fragment that handles POSTs specifically.
> Can you provide a more self-contained fragment. What does the URLConf
> entry look like that will be used to hand things to a simplified view
> that shows the behaviour you're seeing? If we could see the URL Conf
> entry and the entire view (simplified to remove everything but the
> minimal information), that would certainly help.
>
> I will confirm what Alex mentioned, however, Django does not, by default
> do anything that you've described. There is the CommonMiddleware
> behaviour of redirecting to a slash appended URL, but you've mentioned
> that you've ruled that out. I can't think of any other middleware that
> might be doing what you've suggested, but if you've added any middleware
> that would be worth mentioning as well.
>
> Also, does the code execution get to your view before you're seeing this
> redirect? Put some debugging prints in to see whether this is happening.

Sorry, this was completely my fault. Turns out I had accidentally
placed my submit
button inside an achor tag. Removing that's fixed the problem.

Thanks for the help.

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



When updating a model instance, list changed fields from inside save()?

2009-04-27 Thread JK Laiho

Something I don't know how to do in an elegant fashion:

Given a model instance that already exists in the database and is
about to be updated (i.e. some columns of the DB row are changed), is
there a way for the instance's save() method to see what fields have
been changed?

I'm writing an app where a custom change log entry must exist for each
model instance change. Assume this code:

- - - - -

class SomeModelChangeLog(models.Model):
somemodel = models.ForeignKey('SomeModel')
message = models.CharField(max_length=255) # maybe a TextField
instead, depends.
created = models.DateTimeField(default=datetime.datetime.now(),
editable=False)


class SomeModel(models.Model):
name = models.CharField()
created = models.DateTimeField(default=datetime.datetime.now(),
editable=False)
(...etc...)

def save(self, force_insert=False, force_update=False):
if self.pk:
# Somehow find out what fields are about to change, create
a new instance of a change log entry model
SomeModelChangeLog.objects.create(message="...")
super(SomeModel, self).save(force_insert, force_update)


sm_foo = SomeModel.objects.create(name="Just some model")
# Do something completely different here, maybe in a completely
different request
# ... time passes ...
sm_bar = SomeModel.objects.get(name="Just some model")
sm_bar.name = "Just some random model"
sm_bar.save()

- - - - -

For the above scenario, I want to construct a change log message that
says something like: "name was changed from 'Just some model' to 'Just
some random model' by [LoggedInUsername]". As the code indicates, this
would happen inside the save() method of SomeModel.

The thing I can't figure out is this: when the object is retrieved as
sm_bar and the 'name' field is changed (but before running save()), is
there any way to "see through" the new 'name' in the instance to
retrieve the old 'name' still in the database? When entering save(),
the in-database values could then be rather trivially compared to the
fresh instance values to construct the change log entry. Of course,
this would have to work for any model with an arbitrary number of
fields and an arbitrary number of field changes.

I have a hunch that 
http://docs.djangoproject.com/en/dev/ref/models/instances/#what-happens-when-you-save
is the way to a solution, but it's not coming to me right now.

Thanks in advance for any help!
--~--~-~--~~~---~--~~
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: MySQL issues

2009-04-27 Thread google torp

Hi.

I haven't used Django with mysql, but judging from your error
it sounds like you haven't created the database in mysql. Django
probably cannot create a db like it can when you use sqlite, as it's
only a file anwyays. So you need to use your mysql tool
phpmyadmin or whatever you use and create the db and then
you can run syncdb. If that doesn't fix the problem, you have a
lot more interesting problem.

~Jakob

On 27 Apr., 10:33, 83nini <83n...@gmail.com> wrote:
> Hi guys,
>
> I'm working on the tutorial onwww.djangobook.com.
> I've created a database using "manage.py starapp books" then i
> modified the "models.py" file to include classes where each class
> represents a column in the database. then i modified the "settings.py"
> file to include the following:
>
> DATABASE_ENGINE = 'mysql'
> DATABASE_NAME = 'books'
> DATABASE_USER = 'Lina'
> DATABASE_PASSWORD = 'somepassword'
> DATABASE_HOST = 'localhost'
> DATABASE_PORT = '3306'
>
> and:
>
> INSTALLED_APPS = (
>     #'django.contrib.admin',
>     'helloworld.books',
>     #'django.contrib.auth',
>     #'django.contrib.contenttypes',
>     #'django.contrib.sessions',
>     #'django.contrib.sites',
> )
>
> should i be good to go or what? why do i get the long long long error
> that ends with:
> _mysql_exceptions.OperationalError: (1049, "Unknown database 'books'")
>
> when i try to validate the database using "C:\path to django
> project folder...> python manage.py validate"
>
> I really need and appreciate your help.
>
> cheers,
> Lina
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



MySQL issues

2009-04-27 Thread 83nini

Hi guys,

I'm working on the tutorial on www.djangobook.com.
I've created a database using "manage.py starapp books" then i
modified the "models.py" file to include classes where each class
represents a column in the database. then i modified the "settings.py"
file to include the following:

DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'books'
DATABASE_USER = 'Lina'
DATABASE_PASSWORD = 'somepassword'
DATABASE_HOST = 'localhost'
DATABASE_PORT = '3306'

and:

INSTALLED_APPS = (
#'django.contrib.admin',
'helloworld.books',
#'django.contrib.auth',
#'django.contrib.contenttypes',
#'django.contrib.sessions',
#'django.contrib.sites',
)

should i be good to go or what? why do i get the long long long error
that ends with:
_mysql_exceptions.OperationalError: (1049, "Unknown database 'books'")

when i try to validate the database using "C:\path to django
project folder...> python manage.py validate"

I really need and appreciate your help.

cheers,
Lina
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Populating an ImageField from an url

2009-04-27 Thread Fabien

Hello,

I'm trying to populate an ImageField with the content of an image from
it's url. I'm trying with the following code :

---
# image_uri is the URL of my image
# new_photo.photo is the ImageField field of my new_photo instance
current_file = File(urllib.urlopen(image_uri))
current_file.name = os.path.basename(image_uri)
new_photo.photo.save(os.path.basename(image_uri),current_file)
---

but I get an AttributeError : addinfourl instance has no attribute
'name'. Has anyone an idea on how to solve that ?

Thanks
-- 
Fabien

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



Replacing the standard User class with a custom one

2009-04-27 Thread Emmanuel Surleau

Hello,

Apologies in advance, I'm sure this query pops up regularly.

I'd like to replace the default User class which comes with Django's 
authentication system (for my application, users login via email/password, not 
login/password, so it's not only a matter of adding fields).

Is there an easy way to do it? Or should I just roll my own and give on the 
default authentication system and (sniff) admin site?

Cheers,

Emm

--~--~-~--~~~---~--~~
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 model request trim analog

2009-04-27 Thread Mike RA9FTM

Hi all

Is there any analog of SQL trim() function in SELECT query?
I need to remove spaces in strings.


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