Django 1.2 release candidate available

2010-05-05 Thread James Bennett
Tonight we're proud to announce, finally, the first Django 1.2 release
candidate. If all goes well, it will also be the *only* release
candidate, and Django 1.2 final will release one week from today.

For more information, consult:

* The Django project weblog:
http://www.djangoproject.com/weblog/2010/may/05/12-rc-1/
* The release notes: http://docs.djangoproject.com/en/dev/releases/1.2-rc-1/

-- 
"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-us...@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: Variable-length forms

2010-05-05 Thread Peter
Thanks.  I'd totally misread what that page was about.  Now I see it's
basically what I want.

Cheers.

On May 4, 9:02 am, Shawn Milochik  wrote:
> http://docs.djangoproject.com/en/1.1/topics/forms/formsets/
>
> That ought to help out.
>
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Using the FormWizard with models

2010-05-05 Thread Wiiboy
Hi guys,
Another question about the FormWizard: is it possible to provide an
existing instance of a model for the forms in the wizard?

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



Re: Can I map authenticated users to specific databases via a database Router?

2010-05-05 Thread Russell Keith-Magee
On Thu, May 6, 2010 at 7:58 AM, Parker
 wrote:
> I'm trying to port part of an existing application to Django.  In the
> other application, each user has their data stored on separate
> databases with identical schemas.
>
> For example, if we have users A, B and C, there are 3 databases
> ("DatabaseA", "DatabaseB", "DatabaseC") each having two tables:
> blog_entries and blog_comments
>
> Ideally I'd like to write a single application into which all 3 users
> can login in.  From here on out, all of the interactions with the
> database should be routed to database specific to that user.  That is
> to say, UserA should only ever be able to insert and update data in
> DatabaseA and UserB should only be able to access DatabaseB.
>
> From a coding perspective, I'd like to leverage Django's multiple
> database support and implement this routing via the DATABASE_ROUTERS
> setting or as a ModelManager so that database I'm accessing abstracted
> away from the code.  That is to say, I can write
> BlogEntries.objects.all() and always return only those blog entries
> for the currently authenticated user.
>
> Is this type of routing or model management possible with Django?
> Should I consider using a site-specific settings.py file simpler to
> what's discussed here: 
> http://www.huyng.com/archives/franchising-running-multiple-sites-from-one-django-codebase-2/394/

What you're describing is "sharding" - splitting your database into
multiple shards, with each shard containing a subset of the full data
set. You should be able to write a sharding router that takes the hint
object information that is provided to the router, and use the pk of
the hint object to determine which shard should service the read and
write queries.

There are some complications in this; for example, finding a user in
the first place when you only know the username, but not the pk --
since the router will need a primary key to find the right shard,
you'll need to manually poll all the shards to find a user (unless
shard allocation is based on a hash of some other property of the user
object).

I would also point out that while this *should* be possible in theory,
it hasn't been the subject of extensive testing, so in practice, I
won't be surprised if you have difficulties. If you do, I'm certainly
interested in hearing any feedback and suggestions on modifications we
can make to accomodate sharding as a use case.

The "site specific settings" approach is a solution to a different
problem entirely. That's trying to cover the idea of having three
almost identical 'sites' with different frontend, but the same
backend. For example, consider a franchised news operation that runs a
news website for three cities; each city has the same news gathering
requirements, but the actual stories will be slightly different, and
the front end will need to be branded separately.  Using site-specific
settings, you could run all three news sites out of the same machine,
the same database, and the same codebase, but maintain separate
appearance and content.

Yours,
Russ Magee %-)

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



Can I map authenticated users to specific databases via a database Router?

2010-05-05 Thread Parker
I'm trying to port part of an existing application to Django.  In the
other application, each user has their data stored on separate
databases with identical schemas.

For example, if we have users A, B and C, there are 3 databases
("DatabaseA", "DatabaseB", "DatabaseC") each having two tables:
blog_entries and blog_comments

Ideally I'd like to write a single application into which all 3 users
can login in.  From here on out, all of the interactions with the
database should be routed to database specific to that user.  That is
to say, UserA should only ever be able to insert and update data in
DatabaseA and UserB should only be able to access DatabaseB.

>From a coding perspective, I'd like to leverage Django's multiple
database support and implement this routing via the DATABASE_ROUTERS
setting or as a ModelManager so that database I'm accessing abstracted
away from the code.  That is to say, I can write
BlogEntries.objects.all() and always return only those blog entries
for the currently authenticated user.

Is this type of routing or model management possible with Django?
Should I consider using a site-specific settings.py file simpler to
what's discussed here: 
http://www.huyng.com/archives/franchising-running-multiple-sites-from-one-django-codebase-2/394/

Thank you
Parker

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Make MPs answer to us

2010-05-05 Thread Russell Keith-Magee
On Thu, May 6, 2010 at 3:04 AM, Darren Mansell  wrote:
>
> It's election day tomorrow. This is a great web site for lots of info about 
> what's really going on:
> [http://www.38degrees.org.uk]

This is a forum about using Django. The site you reference is in no
way relevant to that topic (as far as I can make out, it's written in
PHP).

Furthermore, this a forum where the vast majority of readers are not
eligible to vote in the UK elections.

While I heartily endorse the message that you should vote when
appropriate in your particular jurisdiction, and be well informed when
doing so, django-users isn't the right place to start promoting your
political viewpoints. Please don't do this again.

Yours,
Russ Magee %-)

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



set_cookie seemingly adding double quotes to cookie value

2010-05-05 Thread Keijik
Hi,

I'm pretty new to Django development.

I have a page where I set some cookies based on responses to a POST.
I'm finding that for certain values, set_cookie is resulting in the
cookie value being enclosed in double quotes.  This seems to happen
for longer values with non-alphanumeric characters.

Some snippets below:

response_params =
urlparse.parse_qs(urllib2.urlopen(request).read())


t = loader.get_template('foo.html')
response = HttpResponse(t.render({ }))
response.set_cookie('c1', response_params['v1'][0])
response.set_cookie('c2', response_params['v2'][0])

This results in a response like:

Set-Cookie: c1="Foo.Bar:1"; Path=/
Set-Cookie: c2=1; Path=/

How do I prevent the c1 value from having the double quotes around
it?  I don't have the same problem with c1.

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



Admin pre-save hooks

2010-05-05 Thread Thomas Neumeier

Hi,

I've got two apps, called A and B.
A has a model called X and B has model called Y.
B hooks into the X's save-Method via the pre_save-Signal and throws an 
IntegrityError under dertain conditions.
Everything like in: 
http://docs.djangoproject.com/en/dev/ref/signals/#ref-signals

This works perfectly.
Now I want the Admin to react on this IntegrityError.
This is no problem for Y, because i can override the AdminForm and throw 
a ValidationError in the clean_field method.


But how can i make the admin of A react on the IntegrityError without 
touching As admin.py?


Thanks
Thomas

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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.



Password reset email sent several times

2010-05-05 Thread newbiedjango
Hi All,

I am using the django-registration app and when try to send a password
reset email it sends 5 mails at once when its suppose to send it only
once.
Can anyone who has faced this problem or anyone who knows how to
rectify this.
I am a newbie in django so please go easy.
Many 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-us...@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.



Disabling (or find a workaround for) the comment security checks

2010-05-05 Thread Federico Capoano
Hello to all,

I've just launched my new web-site powered by django and i'm very
satisfied.

I've implemented StaticGenerator to improve the performance and
loading speed and I have to admit is brilliant.

Unfortunately i've noticed the comment system doesn't work. This
happens because the pages of the blog are saved as static html pages,
so the timestamp and csfr security stuff are the one saved when the
page was generated.

I gotta find a fix for this, because I really want my blog pages to be
saved as static html cos this is the best solution to obtain fast
loading speed without overloading my little VPS.

I think I can generate the timestamp with javascript, but what about
the other two fields (csrfmiddlewaretoken and security hash)?

If you want to take a look closely this is the url: 
http://nemesisdesign.net/blog/
I hope i'm not breaching any rule by posting the url.

Thanks
Federico

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 not displaying validation errors [solved]

2010-05-05 Thread mhulse
Hi Karen! Thanks so much for your quick reply, I really appreciate
it. :)

> form.is_valid() is what annotates the existing form with error information
> in the case where there are errrors. However, if form.is_valid() returns
> False, the code here immediately overwrites the existing (now annotated with
> error information) form and replaces it with a newly-created blank form, so
> there will be no errors for the template to display. Get rid of that else
> leg.

Eureka! That did the trick!!!

I swear that every example I looked at today returned an unbound
form. :D

Onward!

Thanks again Karen. You rock!

Cheers,
Micky

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 not displaying validation errors

2010-05-05 Thread Karen Tracey
On Wed, May 5, 2010 at 6:04 PM, mhulse  wrote:

>if form.is_valid(): # All validation rules pass.
>
># Q objects/pagination here...
>
>else:
>
>form = SearchForm()
>


form.is_valid() is what annotates the existing form with error information
in the case where there are errrors. However, if form.is_valid() returns
False, the code here immediately overwrites the existing (now annotated with
error information) form and replaces it with a newly-created blank form, so
there will be no errors for the template to display. Get rid of that else
leg.

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-us...@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 not displaying validation errors

2010-05-05 Thread mhulse
Hi,

I have spent half the day googling and testing my code with no luck
getting an error message to appear via my template. I am hoping ya'll
could provide a little assistance. :)

forms.py:



class SearchForm(forms.Form):
q = forms.CharField(
max_length = 128,
min_length = 2,
label = 'Keywords',
help_text = 'This is a required field'
)
def clean_q(self):
cd = self.cleaned_data['q']
if not cd:
raise forms.ValidationError("Please enter a search 
term.")
return cd
# More fields defined here 



views.py:



def search(request):

pg = request.GET.get('page', '1')
results = ''
form = SearchForm()

if request.method == 'GET': # If the form has been submitted...

form = SearchForm(request.GET) # A form bound to the GET data.

if form.is_valid(): # All validation rules pass.

# Q objects/pagination here...

else:

form = SearchForm()

return render_to_response(
'folder/search.html',
{
'form': form,
'results': results,
}
)



search.html (nothing is output in any of the below tags):



{{ form.non_field_errors }}
{% if form.errors %}
{{ form.errors|pluralize }}
{% endif %}
{% for field in form %}
{{ field.error }}
{{ field.field.error }}
{% endfor %}



I must be missing something really obvious here! :D

Almost all of the examples of django forms and validation use POST
data... Is there something about GET data that makes error handling
different?

TIA!

Cheers,
Micky

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 ValidationError for DateField

2010-05-05 Thread Karen Tracey
On Wed, May 5, 2010 at 5:33 PM, LeeRisq  wrote:

> This is mostly me just venting, but why is it if you run a query like
> this:
>
> a = Model.objects.get(pk=1)
>
> Which has an attribute with an output of:
>
> a.date = None
>
> I pass that to a template, change some other attribute and then
> attempt to pass it back in:
>
> date = request.GET['a.date']
> b = Model.object.get(date=date)
>
> And I get a ValidationError stating that I must enter a date in a
> valid format. sigh
> Shouldn't the output validate as input? Unless someone knows of a good
> reason for this?
>

If you try:

Model.object.get(date=None)

from a Python manage.py shell I believe you will see  that would be
accepted. The problem is you are not getting back Python None from
request.GET['a.date']. The problem is likely in the round trip to the
browser and back and you've rather left out a lot of details in "pass that
to a template...pass it back in": what exactly are you doing here? What gets
passed to the template and what is in the template? (And are you really
processing changed data values via GET and not POST?)

Note if you were using a ModelForm for this model to handle display and
update, it would just work. The form field for the date would clean the
submitted data (an empty string, since HTML has no "None") and normalize the
empty submitted value to Python None.

One other note: Model.object.get(date=None) looks a bit dangerous. Are you
sure you will only ever have exactly one of these models with no date?
Attempting to get on a field that is not guaranteed to be unique will raise
an exception when zero or more than one matches are found.

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-us...@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: Noob questions: Syntax, Python listserv, utility/helper methods?

2010-05-05 Thread mhulse
> HTH,

Very much so!

Thanks so much Peter, I really appreciate your help. :)

One last question: I have been working with django-schedule (just been
doing the templating) and I noticed that the author of that code
prepended underscores to all of his included files:

...
_detail.html
_dialogs.html
_event_options.html
...
{% include "schedule/_dialogs.html" %}

GitHub django-schedule "templates/":


I thought that was a nice way of separating include files from
everything else. Is this something that other Python/Django folks
prefer?

Thanks again for all of your assistance and guidance. I owe you
one. :)

Have a great day!
Cheers,
Micky

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 ValidationError for DateField

2010-05-05 Thread LeeRisq
This is mostly me just venting, but why is it if you run a query like
this:

a = Model.objects.get(pk=1)

Which has an attribute with an output of:

a.date = None

I pass that to a template, change some other attribute and then
attempt to pass it back in:

date = request.GET['a.date']
b = Model.object.get(date=date)

And I get a ValidationError stating that I must enter a date in a
valid format. sigh
Shouldn't the output validate as input? Unless someone knows of a good
reason for this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: QuerySet.distinct and aggregates

2010-05-05 Thread Wedg
The Beta name field is actually an FK to another model, like this:
Payment (Alpha) <- AppliedPayment (Gamma) -> Invoice (Beta) ->
Location (Name)

The actual call I had tried was
Payment.objects.filter(appliedpayment__invoice__location=loc).distinct().aggregate(Sum('amount'))
(where amount is a field on Payment). I could do
AppliedPayment...aggregate(...), but unfortunately the AppliedPayment
splits the 'amount' into several values (based on revenue type), which
would mean doing several aggregate calls and summing them, which I've
already done when it seemed appropriate (and I just discovered while
writing this that aggregate can take more than one argument, but I
don't know if that results in a single query). For now, when I know
there's generally going to be less than a dozen instances, I've just
done the processing in python, which I'm sure will work fine.

I was hoping for an elegant solution for when I know there's going to
be several thousand plus instances (or hundreds of thousands after a
year or two of deployment). So in the end, I guess I can work with it,
but mostly I was hoping to find out whether the whole respecting
distinct() thing could be made to happen.

Dunno if it's worthwhile filing a ticket for it, or if there is one.
Or maybe just a doc ticket for mentioning explicitly that aggregate
ignores distinct.

Thanks very much for your help.

On May 5, 3:04 pm, zinckiwi  wrote:
> I'd try both and compare the processing time. What is the nature of
> the Beta.name equivalent in your actual model? If it is a simple field
> (e.g. INT) I doubt the overhead would be too bad. What might be
> tripping me up is having your Gamma being linked to your Alpha through
> an intermediate model. Since you mentioned Alpha is a payment model,
> presumably Gamma is one of the constituent parts -- so why would there
> not be a direct FK relationship between the two? (Or at least a one
> way FK relationship through the intermediate model e.g. Beta->Gamma-
>
> >Alpha.)
>
> On May 5, 12:31 pm, Wedg  wrote:
>
>
>
> > > qs = Alpha.objects.filter(gamma__beta__name='Beta').distinct())
> > > id_list = [x.id for x in qs]
> > > total =
> > > Alpha.objects.filter(id__in=id_list).aggregate(total=models.Sum('id')).get(
> > >  'total')
>
> > I'm sure this approach would work fine, however I feel like it might
> > be a performance issue when the Alpha model (in my real world case, a
> > Payment model) reaches a few thousand instances in that id_list. Maybe
> > I'm wrong. If it were only a few dozen or even a few hundred, I would
> > just do the processing in python and not worry about it. On the other
> > hand, maybe python has some fancy optimizations for list comprehension
> > that I'm not aware of, or DBs for processing large WHERE ... IN ...
> > clauses.
>
> > I guess I'll just start writing up the SQL for now and secretly hope
> > that someone chimes in with a better solution.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 object representing the current user

2010-05-05 Thread Daniel Roseman
On May 5, 9:30 pm, Paul  wrote:
> I have the following model (stripped of comments and __unicode__ for
> brevity) which defines  a comment in my Django app (I'm not using the
> comment module provided with Django for various reasons):
>
> class Comment(models.Model):
>   comment = models.TextField()
>   added_by = models.ForeignKey(User)
>   added_date = models.DateTimeField(auto_now_add = True)
>   approved = models.BooleanField()
>
> class CommentForm(ModelForm):
>   class Meta:
>     model = Comment
>     fields = ['comment']
>
> I also have a simple template which just displays the CommentForm
> (i.e. a textarea within a form element) and the action of the form is
> set to the following view:
>
> def add_comment(request):
>   if request.method == 'POST' and request.user.is_authenticated():
>     comment = Comment()
>     comment.added_by = request.user
>     comment.approved = False
>
>     comment_form = CommentForm(request.POST, instance = comment)
>
>     if comment_form.is_valid():
>       comment.save()
>       return HttpResponseRedirect('/')
>
> However, when I submit the form I get the following error:
>
> (1048, "Column 'added_by_id' cannot be null")
>
> I'm sure request.user must be set, because it is being accessed
> earlier in the code (request.user.is_authenticated), so I'm not sure
> why this error is appearing. Am I doing something obviously wrong? I'm
> new to both Django and Python so I am picking things up as I go along.
>
> Thanks in advance for any pointers.

What's probably happening is that because you're instantiating the
object first, then passing it to the form, the form is overwriting all
the attributes. There are two ways of fixing this: either exclude the
added_by field in the form Meta class:
  exclude = ('added_by',)
or, and this is probably better, set the added_by and approved fields
when you come to save:
if comment_form.is_valid():
  comment.save(commit=False)
  comment.added_by = request.user
  comment.approved = False
  comment.save()
--
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-us...@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 object representing the current user

2010-05-05 Thread Paul
I have the following model (stripped of comments and __unicode__ for
brevity) which defines  a comment in my Django app (I'm not using the
comment module provided with Django for various reasons):

class Comment(models.Model):
  comment = models.TextField()
  added_by = models.ForeignKey(User)
  added_date = models.DateTimeField(auto_now_add = True)
  approved = models.BooleanField()

class CommentForm(ModelForm):
  class Meta:
model = Comment
fields = ['comment']

I also have a simple template which just displays the CommentForm
(i.e. a textarea within a form element) and the action of the form is
set to the following view:

def add_comment(request):
  if request.method == 'POST' and request.user.is_authenticated():
comment = Comment()
comment.added_by = request.user
comment.approved = False

comment_form = CommentForm(request.POST, instance = comment)

if comment_form.is_valid():
  comment.save()
  return HttpResponseRedirect('/')

However, when I submit the form I get the following error:

(1048, "Column 'added_by_id' cannot be null")

I'm sure request.user must be set, because it is being accessed
earlier in the code (request.user.is_authenticated), so I'm not sure
why this error is appearing. Am I doing something obviously wrong? I'm
new to both Django and Python so I am picking things up as I go along.

Thanks in advance for any pointers.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: permissions at per specific object instance

2010-05-05 Thread Dj Gilcrease
On Wed, May 5, 2010 at 4:09 PM, zweb  wrote:
> I need to build "permissions at per specific object instance" for my
> app.
>
> Anyone has already done it ?  Also it says django developers are
> already discussing it..
>
> You can please refer me to the threads or blog posts on it.

http://djangoadvent.com/1.2/object-permissions/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: permissions at per specific object instance

2010-05-05 Thread Peter Herndon
http://packages.python.org/django-authority/

or, an alternative:

http://pypi.python.org/pypi/django-objectpermissions/

---Peter Herndon

On May 5, 2010, at 4:09 PM, zweb wrote:

> "Permissions are set globally per type of object, not per specific
> object instance. For example, it's possible to say "Mary may change
> news stories," but it's not currently possible to say "Mary may change
> news stories, but only the ones she created herself" or "Mary may only
> change news stories that have a certain status, publication date or
> ID." The latter functionality is something Django developers are
> currently discussing."
> 
> I need to build "permissions at per specific object instance" for my
> app.
> 
> Anyone has already done it ?  Also it says django developers are
> already discussing it..
> 
> You can please refer me to the threads or blog posts on it.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



permissions at per specific object instance

2010-05-05 Thread zweb
"Permissions are set globally per type of object, not per specific
object instance. For example, it's possible to say "Mary may change
news stories," but it's not currently possible to say "Mary may change
news stories, but only the ones she created herself" or "Mary may only
change news stories that have a certain status, publication date or
ID." The latter functionality is something Django developers are
currently discussing."

I need to build "permissions at per specific object instance" for my
app.

Anyone has already done it ?  Also it says django developers are
already discussing it..

You can please refer me to the threads or blog posts on it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: cascade deletion happens before pre_delete signal is sent?

2010-05-05 Thread msoulier
On Apr 3, 6:23 pm, Tomasz Zieliński 
wrote:
> I believe that this question was asked on this group a long time ago,
> and the answer was that pre_delete signal was fired *before* actual
> deletion occured,
> but *after* objects were collected for deletion (i.e. after list of
> objects that were to be deleted
> was created - you can think of this list as of "deletion tree" show in
> Django admin).
>
> Writing this, I don't know if you've observed the same problem.

It seems that way. The bottom line is that pre_delete is not helping
to prevent unintended deletion. To solve this issue I've had to define
my own signal and send that in my model's delete method.

Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: QuerySet.distinct and aggregates

2010-05-05 Thread zinckiwi
I'd try both and compare the processing time. What is the nature of
the Beta.name equivalent in your actual model? If it is a simple field
(e.g. INT) I doubt the overhead would be too bad. What might be
tripping me up is having your Gamma being linked to your Alpha through
an intermediate model. Since you mentioned Alpha is a payment model,
presumably Gamma is one of the constituent parts -- so why would there
not be a direct FK relationship between the two? (Or at least a one
way FK relationship through the intermediate model e.g. Beta->Gamma-
>Alpha.)

On May 5, 12:31 pm, Wedg  wrote:
> > qs = Alpha.objects.filter(gamma__beta__name='Beta').distinct())
> > id_list = [x.id for x in qs]
> > total =
> > Alpha.objects.filter(id__in=id_list).aggregate(total=models.Sum('id')).get( 
> > 'total')
>
> I'm sure this approach would work fine, however I feel like it might
> be a performance issue when the Alpha model (in my real world case, a
> Payment model) reaches a few thousand instances in that id_list. Maybe
> I'm wrong. If it were only a few dozen or even a few hundred, I would
> just do the processing in python and not worry about it. On the other
> hand, maybe python has some fancy optimizations for list comprehension
> that I'm not aware of, or DBs for processing large WHERE ... IN ...
> clauses.
>
> I guess I'll just start writing up the SQL for now and secretly hope
> that someone chimes in with a better solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Open source CMS (if based on Django better)

2010-05-05 Thread Jonatan.mv
What would be you recommended CMS?. Could you please give some reasons
(pro and cons)?.

I'm investigating on these:

- PyLucid v0.8.x stable, v0.9 alpha
- FeinCMS v1.1.0 stable
- django-simplecms
- django-cms-2.0 2.0.2 stable , 2.1 alpha
- google-sites

By the way... I like how google-sites work, ¿Do you know the
technology they use?

Thanks in advance !

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



How to override a method in auth backend.py

2010-05-05 Thread lray

We store groups/ roles in another table due to legacy reasons.

I need to override following method in auth backend, by my own method
to get permissions from a custom role permission table. How can I do
it?


>>> override following method to get permissions from legacy table 
>>> role_permissions  

def get_group_permissions(self, user_obj) in
http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/backends.py

def get_group_permissions(self, user_obj):
23  """
24  Returns a set of permission strings that this user has
through his/her
25  groups.
26  """
27  if not hasattr(user_obj, '_group_perm_cache'):
28  perms = Permission.objects.filter(group__user=user_obj
29  ).values_list('content_type__app_label',
'codename'
30  ).order_by()
31  user_obj._group_perm_cache = set(["%s.%s" % (ct, name)
for ct, name in perms])
32  return user_obj._group_perm_cache
33

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Syntax for displaying field values from parent model(s) in a template?

2010-05-05 Thread Daniel Roseman
On May 5, 6:27 pm, Derek  wrote:
> I  have set of models, with relationships D -> C -> B -> A, where the
> "->" indicates a "many to one" relationship.
>
> I have been able to create a filtered queryset on child model D, based
> on a value in a parent model A, using the following syntax:
>
> my_query = D.objects.filter(C__B__A__name__icontains = "foo")
>
> where model A has a field called "name".
>
> I need to be able to display the value of the "name" field from A,
> along with the field attribute data from D in a template.
>
> I have therefore added the following to the end of my_query:
>
> .select_related('C__B__A__name')
>
> Assuming the template is called with the context containing:
>
> 'results': my_query
>
> then I can use {{ results.name }}, for example, to retrieve the value
> of the "name" field from model D.
>
> However I am unable to figure out the correct syntax for retrieving
> the value of the "name" field from related model A.
>
> I have tried  {{ results.C.B.A.name }} with no effect?
>
> What is the correct way to do this?
>
> Thanks
> Derek

Firstly, your select_related syntax is wrong. You don't need it to
access related objects, but it does help cut down on db queries.
However, it doesn't go down to field level, so you just want
'C__B__A'.

Secondly, your 'results' object is a queryset, so you *can't* do
'results.name' as you claim. A queryset is a collection of items, not
a single one, so 'results' as a whole doesn't have either 'name' or
'C' attributes. However, once you iterate through the queryset, each
individual item inside it does have both 'name' and 'C' attributes. So
this will work:

{% for result in results %}
{{ result.name }} : {{ result.C.B.A.name }}
{% endfor %}

An easy way of exploring all this is via the shell - you could have
seen the result of your query there, and accessed the individual
objects and their attributes.
--
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-us...@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.



Make MPs answer to us

2010-05-05 Thread Darren Mansell
It's election day tomorrow. This is a great web site for lots of info about 
what's really going on:
[http://www.38degrees.org.uk]
Darren

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



Re: How to adapt some code provided by friend

2010-05-05 Thread Frank
I hate to chime in here but I recently started using Django, quite
successfully. I'm also a consent-student. I fear that you are going to
have a lot of trouble using Django (or anything like it) if you don't
build some basics.

To successfully use a product like Django, basic knowledge of at least
database administration will go along way. I'd also highly suggest you
go though a Intro-to-python book. (The book Dive In To python is
online: http://diveintopython.org/toc/index.html)

Don't get me wrong, you don't need to be an expert -- or even close --
of anything to use these tools. But, some basic knowledge will take
you a long way when trying to determine what a problem might be or how
to go about something.

Regards,
Frank (tOSU)

On May 5, 7:05 am, Etienne Python  wrote:
> Well actually, I copied all of the data (including the database), not only
> the code. But indeed, like you say, the problem is not solved yet just by
> installing mysql.
>
> So I followed the alternative solution you suggested. Now I get another
> error actually: when I run ./manage.py syncdb  like you suggested I get the
> following message in the cmd:
>
> Error: No module named redis_cache.cache
>
> I must admit I'm lost ;-)
>
> 2010/5/5 Daniel Roseman 
>
>
>
> > On May 5, 12:23 pm, Etienne Python  wrote:
>
> > > File "c:\python26\lib\site-packages\django\db\backends\mysql\base.py",
> > > line 13, in 
> > >    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> > > django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> > > module: No module named MySQLdb
>
> > As Georg says, you need to install MySQLdb. However I suspect that
> > that won't solve your problem: if all you've done is copied the Django
> > code from the server, there'll be a whole stack of things you don't
> > have, starting with the database itself. If you need the actual data
> > from the server, you'll need to install MySQL itself as well, then
> > back up the data from the server and restore it to your local
> > database.
>
> > If you don't, you can probably shortcut this whole process by simply
> > using sqlite - in your settings.py, change DATABASE_ENGINE to
> > 'sqlite3' and your DATABASE_HOST to a filename, something like
> > 'data.db'. Then run ./manage.py syncdb to create the empty database.
> > --
> > 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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com
> > .
> >  For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Syntax for displaying field values from parent model(s) in a template?

2010-05-05 Thread Derek
I  have set of models, with relationships D -> C -> B -> A, where the
"->" indicates a "many to one" relationship.

I have been able to create a filtered queryset on child model D, based
on a value in a parent model A, using the following syntax:

my_query = D.objects.filter(C__B__A__name__icontains = "foo")

where model A has a field called "name".

I need to be able to display the value of the "name" field from A,
along with the field attribute data from D in a template.

I have therefore added the following to the end of my_query:

.select_related('C__B__A__name')

Assuming the template is called with the context containing:

'results': my_query

then I can use {{ results.name }}, for example, to retrieve the value
of the "name" field from model D.

However I am unable to figure out the correct syntax for retrieving
the value of the "name" field from related model A.

I have tried  {{ results.C.B.A.name }} with no effect?

What is the correct way to do this?

Thanks
Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Altering object order in formsets with can_order

2010-05-05 Thread Paulo Almeida
Hi,

I'm having a hard time grasping the concept of the can_order argument, when
creating formsets. Once objects are created and saved through the formset,
is it possible to reorder them? Where does the order information get stored?
I tried just adding can_order=True when creating the formset (it's an
inline_formset) and the order fields do show up on the form, but they don't
seem to have any effect. I'm just saving the formset. Should I use "formset.
ordered_forms" to sort them and then save each one individually?

I really need to be able to reorder after saving, because some of these
objects are being created outside forms and I want the users to reorder them
if they want to. If that is not possible with can_order, I think an easy way
to do it would be to have an extra variable in that model, storing the order
(in the form it would work just like the fields created by can_order). Does
that sound reasonable?

Thanks for any help,
Paulo Almeida

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: QuerySet.distinct and aggregates

2010-05-05 Thread Wedg
> qs = Alpha.objects.filter(gamma__beta__name='Beta').distinct())
> id_list = [x.id for x in qs]
> total =
> Alpha.objects.filter(id__in=id_list).aggregate(total=models.Sum('id')).get('total')

I'm sure this approach would work fine, however I feel like it might
be a performance issue when the Alpha model (in my real world case, a
Payment model) reaches a few thousand instances in that id_list. Maybe
I'm wrong. If it were only a few dozen or even a few hundred, I would
just do the processing in python and not worry about it. On the other
hand, maybe python has some fancy optimizations for list comprehension
that I'm not aware of, or DBs for processing large WHERE ... IN ...
clauses.

I guess I'll just start writing up the SQL for now and secretly hope
that someone chimes in with a better solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: AdminField Rendering Question

2010-05-05 Thread geraldcor
Oh of course. Probably the one file I didn't look at. I think a
subclass is in order. Thank you very much for the direction.

Greg

On May 5, 5:01 am, patrickk  wrote:
> there you 
> go:http://code.djangoproject.com/browser/django/trunk/django/contrib/adm...
>
> unfortunately, it´s all hardcoded. if you need to customize the
> widget, you may want to write your own and subclass the given one.
>
> hope that answers your question.
>
> regards,
> patrick
>
> On 5 Mai, 01:43, geraldcor  wrote:
>
>
>
> > Hello all,
>
> > I have been pouring over the django source trying to figure out where
> > the "Currently: "/images/..."" gets added to ImageField upload fields
> > after an image has been uploaded in the admin interface. I wonder this
> > because I would like to do some custom manipulation with the image
> > field and as I was searching for how to do this I just couldn't find
> > anything about how any form fields are rendered for that matter. I
> > understand how they are constructed and how the template is rendered
> > but I can't for the life of me figure out how the actual field is
> > rendered and represented in the html form. Could anyone please offer
> > me some insight into this. I really love the "Currently:" that shows
> > up and I would like to see how it's done.
>
> > Thank you for helping out a very confused person.
>
> > Greg.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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_audit 0.0.2

2010-05-05 Thread Dj Gilcrease
On Wed, May 5, 2010 at 10:49 AM, Gustavo Narea
 wrote:
> On May 5, 3:45 pm, Dj Gilcrease  wrote:
>> I also think Euan Goddard has already registered django-audit on pypi
>> (http://pypi.python.org/pypi/django-audit/0.9/)
>
> That's what I meant, Euan and I work together :)


Ahh ok, well I wont be pushing my audit app to PYPI in the near future
so no worries about naming conflicts there

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: [ANN] django_nav 0.6

2010-05-05 Thread Dj Gilcrease
Now in PYPI
http://pypi.python.org/pypi/django_nav/

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



Re: How to alter the value of a field in admin pages and turn off-autoescaping

2010-05-05 Thread Massimiliano della Rovere
I wanted the date in this format:
%A
%d %B %Y
%H:%M:%S

I found a solution to point #2:

format_data = re.compile(r'(?<=\d)\s(?=[A-Za-z])|(?<=[A-Za-z])\s(?=\d)',
re.LOCALE | re.UNICODE)

list_display = ('x',)

def x(self, row):
return mark_safe(format_data.sub('',
formats.localize(row.call_start)))
x.allow_tags = True

I still have to find out the solution to #1...


On Wed, May 5, 2010 at 12:48, Massimiliano della Rovere
 wrote:
> 1st question) I am trying to change the way some of DateTimeField are
> displayed in the change_list page of the admin site (django 1.2 svn):
> how to do it?
>
> Not knowing which method to define or override in the ModelAdmin
> class, I opted for a different solution:
> I added a string in the list_display tuple and then I defined a
> homonimous method:
>
> list_display = ('x',)
>
> def x(self, row):
> return mark_safe(row.call_start.strftime(u'%Y-%m-%d%H:%M:%S'))
>
> 2nd question) why the "<>" signs in the strings are escaped in the
> change_list page even though they are marked safe?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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_audit 0.0.2

2010-05-05 Thread Gustavo Narea
On May 5, 3:45 pm, Dj Gilcrease  wrote:
> I also think Euan Goddard has already registered django-audit on pypi
> (http://pypi.python.org/pypi/django-audit/0.9/)

That's what I meant, Euan and I work together :)

 - Gustavo.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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_audit 0.0.2

2010-05-05 Thread Dj Gilcrease
On Wed, May 5, 2010 at 10:06 AM, Gustavo Narea
 wrote:
> Hello,
>
> I would suggest you try to register "django_audit" on PYPI and see if
> it allows you to do so.
>
> We had already registered the package"django-audit" (note the hyphen
> instead of an underscore, which is exactly how we've always spelled
> it). I'm not sure if PYPI will let you register "django_audit" because
> when you create Python eggs hyphens are replaced with underscores.

I personally have little to no interest in pushing my project to PYPI
as that would mean I am committed to  maintaining it for others which
I am not at this point. I developed it as an internal solution and
figured it might be useful to other people so put the project up.

I also think Euan Goddard has already registered django-audit on pypi
(http://pypi.python.org/pypi/django-audit/0.9/)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



[ANN] django_nav 0.6

2010-05-05 Thread Dj Gilcrease
Code @ http://code.google.com/p/django-nav/

This is a bug fix release to make conditionals work again.

Before 1.0 is ready to go I want to add the ability to dynamically
generate nav manus either via a DB, Config file, Cache, etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Insert model data into every page (base.html)

2010-05-05 Thread Bill Freeman
See: 
http://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors

On Wed, May 5, 2010 at 10:06 AM, Martin Tiršel  wrote:
> Hello,
>
> I need to insert some data from database onto every page, so I inserted them
> into base.html. Until now, I was using generic views but it doesn't seems to
> be ideal for this case. Is there a way how to achieve this behaviour with
> generic views or I have to insert needed model into every custom view?
>
> I tried it this way, but update() returns None, so it doesn't work, but it
> demonstrates what I am looking for:
>
>
> currency_by_date = {
>    "queryset": Currency.objects.all().order_by('-date', 'currency')[:2],
>    "template_name": "home.html",
>    "template_object_name": "currency",
> }
>
> urlpatterns = patterns('',
>    (r'^$', 'django.views.generic.list_detail.object_list',
>        currency_by_date),
>    (r'^profil_spolocnosti/$',
> 'django.views.generic.list_detail.object_list',
>        currency_by_date.update({"template_name":
> "profil_spolocnosti.html"})),
> ...
>
>
> If I have to use custom views what is the best way to include above queryset
> result into templates without repeating it over every view?
>
> Thank you for your help,
> Martin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: change an object from parent to child

2010-05-05 Thread Steve Bywater
Here is a realistic example: I have a model Employee that is a
subclass of User, the standard django authentication class, and a
model called Supervisor that subclasses Employee.

I have Bob, an instance of Employee, that I want to promote to
Supervisor. So trying to move the Bob object to the child Supervisor
class from its parent Employee class.

I could do this directly through sql by creating a record in
app_supervisor setting employee_ptr_id to the id of the app_employee
record, but I'm hoping that django has more direct support for
migrating a parent object to a child object.

- Steve

On May 4, 4:30 pm, Shawn Milochik  wrote:
> You can't subclass an instance, just a class/object.
>
> Maybe you want a foreign key to place in restaurant.
>
> What are you trying to do?
dard >
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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_audit 0.0.2

2010-05-05 Thread Gustavo Narea
Hello,

I would suggest you try to register "django_audit" on PYPI and see if
it allows you to do so.

We had already registered the package"django-audit" (note the hyphen
instead of an underscore, which is exactly how we've always spelled
it). I'm not sure if PYPI will let you register "django_audit" because
when you create Python eggs hyphens are replaced with underscores.

Cheers,

 - Gustavo.


On May 4, 11:21 am, Dj Gilcrease  wrote:
> On Tue, May 4, 2010 at 4:21 AM, Euan Goddard
>
>  wrote:
> > This is all very well, but should either of these projects get to pypi
> > there's going to be some serious trouble. Since I'm the main author of
> > the "noSQL" django-audit, please let me know how you want to proceed.
> > I'm already using the project in some pre-production code so would
> > rather not rename my project. If you could rename yours that would be
> > really helpful as this clearly a case of two people simultaneously
> > coming up with the same name.
>
> Google code wont let me change the project name without deleting and
> recreating the project so I just added a note to the top
>
> "This is a fairly comprehensive Audit Trail App for use with standard
> RDBMS databases. If you are looking for a solution for NoSQL there is
> a great project by the same name but differing author 
> @https://launchpad.net/django-auditthat uses MongoDB."
>
> and a little NoSQL vs SQL comparison of the two solutions
>
> "Not all of us can use a NoSQL audit solution due to business rules or
> other constraints. Django Audit for MongoDB preserves field type in
> the audit history, which is lost django-audit for SQL. This loss of
> field type is mitigated by the field formatters which allow you to
> record the field how you want to display it to the person reading the
> audit history.
>
> Ultimately the solution you pick will depend on your requirements and
> capabilities, both work, though I believe my solution takes a bit more
> work for the developer to setup and configure on each model then then
> MongoDB solution (have not looked too deeply into the code over there
> as I cannot use MongoDB for the projects I need an Audit history in)"
>
> I also added links to a few of the other audit solutions out there
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Insert model data into every page (base.html)

2010-05-05 Thread Martin Tiršel

Hello,

I need to insert some data from database onto every page, so I inserted  
them into base.html. Until now, I was using generic views but it doesn't  
seems to be ideal for this case. Is there a way how to achieve this  
behaviour with generic views or I have to insert needed model into every  
custom view?


I tried it this way, but update() returns None, so it doesn't work, but it  
demonstrates what I am looking for:



currency_by_date = {
"queryset": Currency.objects.all().order_by('-date', 'currency')[:2],
"template_name": "home.html",
"template_object_name": "currency",
}

urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list',
currency_by_date),
(r'^profil_spolocnosti/$',  
'django.views.generic.list_detail.object_list',
currency_by_date.update({"template_name":  
"profil_spolocnosti.html"})),

...


If I have to use custom views what is the best way to include above  
queryset result into templates without repeating it over every view?


Thank you for your help,
Martin

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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_audit 0.0.2

2010-05-05 Thread Euan Goddard
On May 4, 11:21 am, Dj Gilcrease  wrote:
> Google code wont let me change the project name without deleting and
> recreating the project so I just added a note to the top

That is quite annoying. I hope you can find a good solution to that
problem.

> "This is a fairly comprehensive Audit Trail App for use with standard
> RDBMS databases. If you are looking for a solution for NoSQL there is
> a great project by the same name but differing author 
> @https://launchpad.net/django-auditthat uses MongoDB."

That is very kind of you and I take your point about MongoDB
availability. We are having to adjust our architecture quite
significantly to allow the inclusion of this technology. Annoyingly
the Debian packages for MongoDB aren't fixed, so there is some messing
around with APT to get it to work properly.

> and a little NoSQL vs SQL comparison of the two solutions

I think that's a fair comparison. With Django 1.2 offering multiple
databases, it will be good to be able to potentially store auditing
information in other SQL databases as to no pollute the application
data directly if you care about that sort of thing.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Empty foreign keys in forms after Apache/PostgreSQL reset

2010-05-05 Thread Xanthus
On May 5, 7:54 am, Tom Evans  wrote:
> On Wed, May 5, 2010 at 5:54 AM, Xanthus  wrote:
> > Hi all. I will try do my best to explain my setup and the sequence of
> > actions triggering the issue:
>
> > 1. Machine starts and all is fine.
> > 2. We do the following operations (through and automated script):
> > a. stop Apache
> > b. stop Postgresql
> > c. drop database
> > d. create database again
> > e. restore database from a versioned backup
> > f. remove the application *.pyc files
> > g. start Postgresql
> > h. start Apache
> > 3. We log in again and we see that the foreign key fields in all the
> > forms who have them are empty. In the admin change forms the foreign
> > keys fields are filled correctly. If we restart Apache a few times
> > (random) the problem fixes itself.
>
> > Setup: django 1.2beta1, PostgresSQL 8.4, Apache 2.2.12, application
> > served by mod_wsgi, operating system Ubuntu Linux 9.10 server edition,
> > Python 2.6.4
>
> > Notes: all the models are using a custom model manager (1) who uses
> > threadlocals to get the current authenticated user and do extra
> > filtering. If we remove the use the extra filtering using threadlocals
> > the problem doesn't happen.
>
> > (1)http://dpaste.com/hold/191037/
>
> > Any hints or pointers to debug the problem? Thanks in advance.
>
> How are you managing to drop, recreate, and re-import a database
> whilst postgresql is stopped?

Ha! Good question :-)  Corrected list:

a. stop Apache
b. drop database
c. create database again
d. restore database from a versioned backup
e. stop Postgresql
f. start Postgresql
g. remove the application *.pyc files
h. start Apache

Regards.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: QuerySet.distinct and aggregates

2010-05-05 Thread zinckiwi
> In [29]:
> Alpha.objects.filter(gamma__beta__name='Beta').values('id').aggregate(model 
> s.Sum('id'))
> Out[29]: {}
>
> In [30]:
> Alpha.objects.filter(gamma__beta__name='Beta').values('name').aggregate(mod 
> els.Sum('id'))
> Out[30]: {}

That's odd -- I would have expected #29 to work (though not #30). Must
just be a particular case of mixing values, annotation and aggregation
that doesn't mesh. My suggestion was cobbled together from the parts
about values() and the final section about combining annotation and
aggregation here:

http://docs.djangoproject.com/en/1.1/topics/db/aggregation/#values

I suppose what I'd try next, slightly clunkier but a step short of
having to write SQL, is two queries:

qs = Alpha.objects.filter(gamma__beta__name='Beta').distinct())
id_list = [x.id for x in qs]
total =
Alpha.objects.filter(id__in=id_list).aggregate(total=models.Sum('id')).get('total')

Regards
Scott

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



Re: How to adapt some code provided by friend

2010-05-05 Thread Daniel Roseman
On May 5, 1:05 pm, Etienne Python  wrote:
> Well actually, I copied all of the data (including the database), not only
> the code. But indeed, like you say, the problem is not solved yet just by
> installing mysql.
>
> So I followed the alternative solution you suggested. Now I get another
> error actually: when I run ./manage.py syncdb  like you suggested I get the
> following message in the cmd:
>
> Error: No module named redis_cache.cache
>
> I must admit I'm lost ;-)

Well redis is another third-party system, this time a key-value store
that seems to have been configured as a cache. It *might* be using
this:
http://github.com/sebleier/django-redis-cache
but without asking your friend, I wouldn't know for sure. And of
course once we've done that, there's no telling what other third-party
modules you might need.

I don't suppose there is a requirements.txt file in the project?
That's a nice easy way of setting up a virtual environment with all
the libraries you need. If your friend was very organised he would
have created one to allow you to get set up by simply doing:
pip install -r requirements.txt
(having first installed pip of course).
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to adapt some code provided by friend

2010-05-05 Thread Etienne Python
Well actually, I copied all of the data (including the database), not only
the code. But indeed, like you say, the problem is not solved yet just by
installing mysql.

So I followed the alternative solution you suggested. Now I get another
error actually: when I run ./manage.py syncdb  like you suggested I get the
following message in the cmd:



Error: No module named redis_cache.cache



I must admit I'm lost ;-)

2010/5/5 Daniel Roseman 

> On May 5, 12:23 pm, Etienne Python  wrote:
> >
> > File "c:\python26\lib\site-packages\django\db\backends\mysql\base.py",
> > line 13, in 
> >raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> > django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> > module: No module named MySQLdb
>
> As Georg says, you need to install MySQLdb. However I suspect that
> that won't solve your problem: if all you've done is copied the Django
> code from the server, there'll be a whole stack of things you don't
> have, starting with the database itself. If you need the actual data
> from the server, you'll need to install MySQL itself as well, then
> back up the data from the server and restore it to your local
> database.
>
> If you don't, you can probably shortcut this whole process by simply
> using sqlite - in your settings.py, change DATABASE_ENGINE to
> 'sqlite3' and your DATABASE_HOST to a filename, something like
> 'data.db'. Then run ./manage.py syncdb to create the empty database.
> --
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
>  For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 encoding

2010-05-05 Thread Karen Tracey
On Wed, May 5, 2010 at 6:17 AM, Lukáš  wrote:

> Hey,
>
> I have a little problem with django encoding. I have got everything in
> the DB set as utf8. Now when I get them from db with django, the
> encoding gets broken. For some reason django "thinks" (maybe knows)
> the data is latin1, which wouldnt be a problem if I would tell him to
> use latin1, which fixed encoding in templates.. Now here comes the
> funny stuff.
>

I don't know what you mean by saying Django '"thinks" (maybe knows) the data
is latin1". Django does not assume or have a default charset of latin1
anywhere.

When Django communicates with the database, it sets the connection charset
to utf-8. The database is responsible for converting between whatever
charset is actually used for the data to/from utf-8 for the connection to
Django. You can have, for example, a MySQL database that is using the latin1
charset. MySQL will convert the latin1 data to utf-8 when sending data on
the Django connection, and similarly will convert utf-8 data received on the
connection to latin1 for storage in the database. Django never sees latin1
data: it has set the connection to utf-8 so everything sent and received
from the database is utf-8 encoded.

It's possible you have a mismatch between the actual encoding used in the
database and the charset it is supposedly configured to be. For example,
with MySQL and old Wordpress versions it is apparently easy to get into a
situation where MySQL tables are created as latin1 but the actual encoding
of the data is utf-8. But to track that down you are going to need to be a
lot more specific about what your database is, how it was created and what
programs were responsible for storing the data in it. Alternatively if you
would give specifics of the "classic decoding error" you mention later that
might provide a clue as to what and where, exactly, the mismatch is. You
also mention you have tried to convert the data to utf8 and say it's still
the same: if you would be very specific about what you mean by "tried to
convert the data to utf8" that would help people help you more effectively.

Here are some settings, maybe it helps:
>
>   DATABASE_OPTIONS = {
>  'use_unicode': True,
>  'charset': 'utf8',
>}
>

You don't need this DATABASE_OPTIONS setting (and should delete it to avoid
confusion), unless you are using a very very old (pre 1.0) version of
Django. If you are doing that, my advice is to update to a supported Django
release.

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



Re: How to adapt some code provided by friend

2010-05-05 Thread Etienne Python
ok, I have done that now, but I'm affraid I still get the same
result... :-(

On May 5, 1:26 pm, "ge...@aquarianhouse.com" 
wrote:
> install MySQLdb :)
>
> On May 5, 1:23 pm, Etienne Python  wrote:
>
>
>
>
>
> > On May 5, 12:42 pm, Daniel Roseman  wrote:
>
> > > On May 5, 11:06 am, Etienne Python  wrote:
>
> > > > Hey all,
>
> > > > I'm a real beginner at both Django and Python, so excuse me if my
> > > > question looks silly to you.
>
> > > > A friend of mine did me a huge favour by coding a form for me.
> > > > However, I would like to modify a couple of details in the page.
>
> > > > I have copied the code and the folders linked to the website to my
> > > > computer. However, even though python and django are both installed
> > > > well, when I want to run the server (python manage.py runserver) from
> > > > the directory where I saved the files. It doesn't provide me the
> > > > message:
>
> > > > -
> > > > Validating models...
> > > > 0 errors found.
>
> > > > Django version 1.0, using settings 'mysite.settings'
> > > > Development server is running athttp://127.0.0.1:8000/
> > > > Quit the server with CONTROL-C.
> > > > --
>
> > > > Which I was looking for... :-(
>
> > > > Instead I get a whole number of imports (which might be ok, I don't
> > > > know)
>
> > > > But was frustrates me is that (logically, I guess) when I try to open
> > > > the development server ( by going tohttp://127.0.0.1:8000/), it
> > > > doesn't work...
>
> > > > Would anyone have tips or an idea on how I could get this to work?
>
> > > > Thanks a lot in advance!
>
> > > You're going to have to give more details. What exactly are the error
> > > messages you see?
> > > --
> > > 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-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.-Hidequoted text -
>
> > > - Show quoted text -
>
> > Thanks for your reply!
>
> > When I typehttp://127.0.0.1:8000/inmy browser, I get: "Internet
> > Explorer cannot display the webpage"
>
> > But I suppose you meant the errors/messages I get in the cmd...
>
> > What I get there is:
>
> > 
> > Traceback (most recent call last):
> > File "manage.py", line 11, in 
> >     execute_manager(settings)
> > File "c:\python26\lib\site-packages\django\core\management
> > \__init__.py, line 362, in execute_manager
> >     utility.execute()
> > File "c:\python26\lib\site-packages\django\core\management
> > \__init__.py, line 303, in execute
> >     self.fetch_command(subcommand).run_from_argv(self.argv)
>
> > 
>
> > And it goes on like that for a while and ends with:
>
> > 
>
> > File "c:\python26\lib\site-packages\django\db\backends\mysql\base.py",
> > line 13, in 
> >    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> > django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> > module: No module named MySQLdb
>
> > 
>
> > That's pretty much it...
>
> > Does that help a little more?
>
> > Thanks for your 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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

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



Re: How to adapt some code provided by friend

2010-05-05 Thread Daniel Roseman
On May 5, 12:23 pm, Etienne Python  wrote:
>
> File "c:\python26\lib\site-packages\django\db\backends\mysql\base.py",
> line 13, in 
>    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> module: No module named MySQLdb

As Georg says, you need to install MySQLdb. However I suspect that
that won't solve your problem: if all you've done is copied the Django
code from the server, there'll be a whole stack of things you don't
have, starting with the database itself. If you need the actual data
from the server, you'll need to install MySQL itself as well, then
back up the data from the server and restore it to your local
database.

If you don't, you can probably shortcut this whole process by simply
using sqlite - in your settings.py, change DATABASE_ENGINE to
'sqlite3' and your DATABASE_HOST to a filename, something like
'data.db'. Then run ./manage.py syncdb to create the empty database.
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to adapt some code provided by friend

2010-05-05 Thread ge...@aquarianhouse.com
install MySQLdb :)

On May 5, 1:23 pm, Etienne Python  wrote:
> On May 5, 12:42 pm, Daniel Roseman  wrote:
>
>
>
> > On May 5, 11:06 am, Etienne Python  wrote:
>
> > > Hey all,
>
> > > I'm a real beginner at both Django and Python, so excuse me if my
> > > question looks silly to you.
>
> > > A friend of mine did me a huge favour by coding a form for me.
> > > However, I would like to modify a couple of details in the page.
>
> > > I have copied the code and the folders linked to the website to my
> > > computer. However, even though python and django are both installed
> > > well, when I want to run the server (python manage.py runserver) from
> > > the directory where I saved the files. It doesn't provide me the
> > > message:
>
> > > -
> > > Validating models...
> > > 0 errors found.
>
> > > Django version 1.0, using settings 'mysite.settings'
> > > Development server is running athttp://127.0.0.1:8000/
> > > Quit the server with CONTROL-C.
> > > --
>
> > > Which I was looking for... :-(
>
> > > Instead I get a whole number of imports (which might be ok, I don't
> > > know)
>
> > > But was frustrates me is that (logically, I guess) when I try to open
> > > the development server ( by going tohttp://127.0.0.1:8000/), it
> > > doesn't work...
>
> > > Would anyone have tips or an idea on how I could get this to work?
>
> > > Thanks a lot in advance!
>
> > You're going to have to give more details. What exactly are the error
> > messages you see?
> > --
> > 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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.-Hide quoted text -
>
> > - Show quoted text -
>
> Thanks for your reply!
>
> When I typehttp://127.0.0.1:8000/in my browser, I get: "Internet
> Explorer cannot display the webpage"
>
> But I suppose you meant the errors/messages I get in the cmd...
>
> What I get there is:
>
> 
> Traceback (most recent call last):
> File "manage.py", line 11, in 
>     execute_manager(settings)
> File "c:\python26\lib\site-packages\django\core\management
> \__init__.py, line 362, in execute_manager
>     utility.execute()
> File "c:\python26\lib\site-packages\django\core\management
> \__init__.py, line 303, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>
> 
>
> And it goes on like that for a while and ends with:
>
> 
>
> File "c:\python26\lib\site-packages\django\db\backends\mysql\base.py",
> line 13, in 
>    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> module: No module named MySQLdb
>
> 
>
> That's pretty much it...
>
> Does that help a little more?
>
> Thanks for your 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: How to adapt some code provided by friend

2010-05-05 Thread Etienne Python


On May 5, 12:42 pm, Daniel Roseman  wrote:
> On May 5, 11:06 am, Etienne Python  wrote:
>
>
>
>
>
> > Hey all,
>
> > I'm a real beginner at both Django and Python, so excuse me if my
> > question looks silly to you.
>
> > A friend of mine did me a huge favour by coding a form for me.
> > However, I would like to modify a couple of details in the page.
>
> > I have copied the code and the folders linked to the website to my
> > computer. However, even though python and django are both installed
> > well, when I want to run the server (python manage.py runserver) from
> > the directory where I saved the files. It doesn't provide me the
> > message:
>
> > -
> > Validating models...
> > 0 errors found.
>
> > Django version 1.0, using settings 'mysite.settings'
> > Development server is running athttp://127.0.0.1:8000/
> > Quit the server with CONTROL-C.
> > --
>
> > Which I was looking for... :-(
>
> > Instead I get a whole number of imports (which might be ok, I don't
> > know)
>
> > But was frustrates me is that (logically, I guess) when I try to open
> > the development server ( by going tohttp://127.0.0.1:8000/), it
> > doesn't work...
>
> > Would anyone have tips or an idea on how I could get this to work?
>
> > Thanks a lot in advance!
>
> You're going to have to give more details. What exactly are the error
> messages you see?
> --
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

Thanks for your reply!

When I type http://127.0.0.1:8000/ in my browser, I get: "Internet
Explorer cannot display the webpage"

But I suppose you meant the errors/messages I get in the cmd...

What I get there is:


Traceback (most recent call last):
File "manage.py", line 11, in 
execute_manager(settings)
File "c:\python26\lib\site-packages\django\core\management
\__init__.py, line 362, in execute_manager
utility.execute()
File "c:\python26\lib\site-packages\django\core\management
\__init__.py, line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)



And it goes on like that for a while and ends with:



File "c:\python26\lib\site-packages\django\db\backends\mysql\base.py",
line 13, in 
   raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: No module named MySQLdb



That's pretty much it...

Does that help a little more?

Thanks for your 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Admin custom filters

2010-05-05 Thread tom
sorry to interrupt with no solution, but I have a similar problem:
I wnat to allow choosing mutiple choises : year = 2003 OR year = 2007
or, year = 2003 AND year = 2007.
(something like checkbox)
I guess one can implement the filter from scratch, but I think there
is might be a way to add this functionality to the implemented
list_filter...
 any suggestion will be appreciated!
thanks
tom

On 4 מאי, 00:23, Thales  wrote:
> Good evening,
>
> I am trying to create a custom filter in my admin. It should be in the
> general page Modify.
>
> If a put in the filter_list the content 'project__year', it shows me
> the years avaiable on the right menu and filters well.
>
> But I want to define the default value (the default year selected) and
> the avaiable options (maybe I dont want to show all the years there).
>
> I am sorry it sounds very easy, but I couldn't find inside the
> documentation how can I do it.
>
> Thanks
> Thales
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: AdminField Rendering Question

2010-05-05 Thread patrickk
there you go:
http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/widgets.py#L88

unfortunately, it´s all hardcoded. if you need to customize the
widget, you may want to write your own and subclass the given one.

hope that answers your question.

regards,
patrick


On 5 Mai, 01:43, geraldcor  wrote:
> Hello all,
>
> I have been pouring over the django source trying to figure out where
> the "Currently: "/images/..."" gets added to ImageField upload fields
> after an image has been uploaded in the admin interface. I wonder this
> because I would like to do some custom manipulation with the image
> field and as I was searching for how to do this I just couldn't find
> anything about how any form fields are rendered for that matter. I
> understand how they are constructed and how the template is rendered
> but I can't for the life of me figure out how the actual field is
> rendered and represented in the html form. Could anyone please offer
> me some insight into this. I really love the "Currently:" that shows
> up and I would like to see how it's done.
>
> Thank you for helping out a very confused person.
>
> Greg.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 encoding

2010-05-05 Thread Lukáš
Hey,

I have a little problem with django encoding. I have got everything in
the DB set as utf8. Now when I get them from db with django, the
encoding gets broken. For some reason django "thinks" (maybe knows)
the data is latin1, which wouldnt be a problem if I would tell him to
use latin1, which fixed encoding in templates.. Now here comes the
funny stuff.

But since then I wasnt able to edit anything, because I get the
classic decoding error. So I set it back to utf8, everything is
broken, but I can edit stuff. Now when I edit the broken string, it
will be saved, BUT when I get it out with PHP its, again, latin1.

So this is what happen:

get string from DB with PHP - its utf8
get string from DB with Django - its latin1
save with Django and get it with PHP - its latin1

I cant figure where the problem is. Maybe its the DB, but I dont know
"how" to fix it, because no matter what I do it will break either
Django or PHP. I have tried to convert the data to utf8, but it still
the same.

Here are some settings, maybe it helps:

   DATABASE_OPTIONS = {
  'use_unicode': True,
  'charset': 'utf8',
}

Any ideas?

Regards

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Empty foreign keys in forms after Apache/PostgreSQL reset

2010-05-05 Thread Tom Evans
On Wed, May 5, 2010 at 5:54 AM, Xanthus  wrote:
> Hi all. I will try do my best to explain my setup and the sequence of
> actions triggering the issue:
>
> 1. Machine starts and all is fine.
> 2. We do the following operations (through and automated script):
> a. stop Apache
> b. stop Postgresql
> c. drop database
> d. create database again
> e. restore database from a versioned backup
> f. remove the application *.pyc files
> g. start Postgresql
> h. start Apache
> 3. We log in again and we see that the foreign key fields in all the
> forms who have them are empty. In the admin change forms the foreign
> keys fields are filled correctly. If we restart Apache a few times
> (random) the problem fixes itself.
>
> Setup: django 1.2beta1, PostgresSQL 8.4, Apache 2.2.12, application
> served by mod_wsgi, operating system Ubuntu Linux 9.10 server edition,
> Python 2.6.4
>
> Notes: all the models are using a custom model manager (1) who uses
> threadlocals to get the current authenticated user and do extra
> filtering. If we remove the use the extra filtering using threadlocals
> the problem doesn't happen.
>
> (1) http://dpaste.com/hold/191037/
>
> Any hints or pointers to debug the problem? Thanks in advance.
>

How are you managing to drop, recreate, and re-import a database
whilst postgresql is stopped?

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



How to alter the value of a field in admin pages and turn off-autoescaping

2010-05-05 Thread Massimiliano della Rovere
1st question) I am trying to change the way some of DateTimeField are
displayed in the change_list page of the admin site (django 1.2 svn):
how to do it?

Not knowing which method to define or override in the ModelAdmin
class, I opted for a different solution:
I added a string in the list_display tuple and then I defined a
homonimous method:

list_display = ('x',)

def x(self, row):
return mark_safe(row.call_start.strftime(u'%Y-%m-%d%H:%M:%S'))

2nd question) why the "<>" signs in the strings are escaped in the
change_list page even though they are marked safe?

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



Re: How to adapt some code provided by friend

2010-05-05 Thread Daniel Roseman
On May 5, 11:06 am, Etienne Python  wrote:
> Hey all,
>
> I'm a real beginner at both Django and Python, so excuse me if my
> question looks silly to you.
>
> A friend of mine did me a huge favour by coding a form for me.
> However, I would like to modify a couple of details in the page.
>
> I have copied the code and the folders linked to the website to my
> computer. However, even though python and django are both installed
> well, when I want to run the server (python manage.py runserver) from
> the directory where I saved the files. It doesn't provide me the
> message:
>
> -
> Validating models...
> 0 errors found.
>
> Django version 1.0, using settings 'mysite.settings'
> Development server is running athttp://127.0.0.1:8000/
> Quit the server with CONTROL-C.
> --
>
> Which I was looking for... :-(
>
> Instead I get a whole number of imports (which might be ok, I don't
> know)
>
> But was frustrates me is that (logically, I guess) when I try to open
> the development server ( by going tohttp://127.0.0.1:8000/), it
> doesn't work...
>
> Would anyone have tips or an idea on how I could get this to work?
>
> Thanks a lot in advance!

You're going to have to give more details. What exactly are the error
messages you see?
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How to adapt some code provided by friend

2010-05-05 Thread Etienne Python
Hey all,

I'm a real beginner at both Django and Python, so excuse me if my
question looks silly to you.

A friend of mine did me a huge favour by coding a form for me.
However, I would like to modify a couple of details in the page.

I have copied the code and the folders linked to the website to my
computer. However, even though python and django are both installed
well, when I want to run the server (python manage.py runserver) from
the directory where I saved the files. It doesn't provide me the
message:

-
Validating models...
0 errors found.

Django version 1.0, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
--

Which I was looking for... :-(

Instead I get a whole number of imports (which might be ok, I don't
know)

But was frustrates me is that (logically, I guess) when I try to open
the development server ( by going to http://127.0.0.1:8000/ ), it
doesn't work...

Would anyone have tips or an idea on how I could get this to work?

Thanks a lot in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Managing JS and CSS. Performance by grouping external files

2010-05-05 Thread Jonatan.mv
Thinking in performance (reduce HTTP request) I'm working on the idea
that that each page includes just one JS and one CSS with the required
modules in inside.

¿Do you know any tool to achieve this?
¿How do you recommend to manage external JS and CSS?
I read some about pyjamas but it seem to be complex... Do you think
that pyjamas could help with User Interface and performance? It worth
to study pyjamas?

Thanks in advance !

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Working out some custom API stuff

2010-05-05 Thread Daniel Roseman
On May 5, 4:46 am, Nick  wrote:
> Here's the deal. I'm working on a custom API for moving information
> about. I am stuck at a point in creating my view.
> It might be best just to get into the details.
>
> Here is the model:
>
> class entry(models.Model):
>     question = models.CharField('Question', max_length=200,
> blank=False)
>     answer = models.TextField('Answer', blank=False)
>     answerer = models.CharField("Expert's Name", max_length=100,
> blank=False)
>     credentials = models.CharField ("Expert's Credentials",
> max_length=100, blank=False)
>     published  = models.DateTimeField(auto_now_add=True)
>     updated = models.DateTimeField(auto_now=True)
>     site = models.ForeignKey(Site)
>     section = TagField()
>
> Once a site is picked the feed is narrowed down by id (whether single
> id, list or range), then by section (single or multiple) and finally
> some pagination and count params (I'm not worried about that right
> now). Currently, I am stuck on the section portion. I may be going
> about this all wrong. What I would like is for some URL like:
>
> http://mysite.com/qanda/SITENAME/?sect=THESECTIONNAME
>
> to produce a JSON output of Questions and Answers under that site with
> that section name. Here is my view:
>
> def QandAAPI(request, site):
>     quest = entry.objects.filter(site__name__icontains=site)
>     if 'id' in request.GET:
>         id = request.GET.get('id','')
>         id = id.split(',')
>     else:
>         id = quest.values_list('id', flat=True)
>     if 'sect' in request.GET:
>         sect = request.GET.get('sect','')
>     else:
>         sect = ''
>     quest = quest.filter(id__in=id, section=sect)
>     object = serializers.serialize("json", quest)
>     json = "%s" % object
>     return HttpResponse(json)
>
> Basically, I would like the "else: sect=" to be a WILDCARD so if the
> sect portion of the API isn't explicitly stated then it just pulls
> everything.
>
> What do you think? Raw SQL? I'm a complete bonehead? All opinions/
> advice are welcome.
>

I wouldn't call you a bonehead, but the method you're using to get all
the objects when no id is passed in is... well... special.

The key to doing this sort of filtering is to remember that QuerySets
are lazy, and successive filters can be applied to them without
hitting the database, until the time comes to actually evaluate them.
So what you want to do is to set up the base query at the start of the
method, then further filter it depending on the GET parameters. Then,
if a particular parameter isn't passed in, you simply don't filter on
it. Something like:

def QandAAPI(request, site):
quest = entry.objects.filter(site__name__icontains=site)
if 'id' in request.GET:
ids = request.GET.getlist('id')
quest = quest.filter(id__in=ids)
if 'sect' in request.GET:
sect = request.GET['sect']
quest = quest.filter(section=sect)
json = serializers.serialize("json", quest)
return HttpResponse(json)

(Also note that I'm using getlist for the 'id' parameter - that
enables you to get multiple values from GET parameters, when they are
supplied in the form /myurl/?id=1=2=3, which is the way browsers
automatically do it when submitting forms (rather than ?id=1,2,3).)
--
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-us...@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: SCORM(Sharable Content Object Reference Model) Compliant for Django?

2010-05-05 Thread Zeal
Thanks Skylar. django-scorm-rest-rte has really less documentation for
studying.  Maybe, SCORM is not the hot technology for LMS. Does anyone
use any else LMS technology with Django in the world? I think LMS is
really a hot topic in the future, and even now. If there is any
possibility to ship LMS function in django, Django could be very
strong and resplendence in the future.

BTW, I've successfully deployed PyAmf modules in my Django's project,
this allows me to deploy some Flex(adobe) project   which will catch
the data from Django and return more user-friendly interface to the
end-user. (Django is really an amazing framework)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 1.2 and legacy database

2010-05-05 Thread Xavier Ordoquy
Hello,

I'm seriously considering django 1.2 for a project which uses several databases.
However, I still got an issue with django 1.2 about legacy database.
I do have many to many relation that goes throught and table without primary 
key.
I don't want to use an intermediate model since it adds absolutely nothing.

I used http://www.djangosnippets.org/snippets/962/ for supporting legacy 
database with django 1.1 but I can't get it working for 1.2 correctly (I can 
only get read but writes don't work).

Has someone a similar code snippet for Django 1.2 ?

Regards,
Xavier Ordoquy.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: TypeError with a Decimal Field

2010-05-05 Thread JonathanB
Yep, see I knew I was doing something simple wrong. The real irony is,
returning just the grade was a placeholder till I came up with a
better idea of exactly what I wanted there Thank you!

On May 4, 9:40 pm, Daniel Roseman  wrote:
> On May 4, 1:15 pm, JonathanB  wrote:
>
>
>
>
>
> > I'm working on a Grade Book program for my personal use. Here is the
> > relevant class from my models.py file:
>
> > class Grade(models.Model):
> >         student = models.ForeignKey(Student)
> >         assignment = models.ForeignKey(Assignment)
> >         grade = models.DecimalField(max_digits=5, decimal_places=2)
>
> >         def __unicode__(self):
> >                 return self.grade
>
> > I get the following error when I try to enter something using the
> > admin interface (all the other models would save without issue): I'm
> > trying to put in "10" or "10.0". I want to use a Decimal field to
> > allow for 1/2 points (such as if they get the right word but the wrong
> > spelling, earning a 9.5). Below is the copy/paste from the Error page
> > I get when I click "Save":
>
> 
>
> > Exception Type: TypeError at /admin/grades/grade/add/
> > Exception Value: coercing to Unicode: need string or buffer, Decimal
> > found
>
> > So, what have I missed? Do I need to import Decimal someplace? And if
> > so, where? admin.py?
>
> The problem is in your __unicode__ method. As the name implies, it
> should always actually return a unicode value, but you're just
> returning the value of self.grade, which is decimal. To be safe,
> Python doesn't automatically coerce anything that's not a string to
> unicode - you have to do it explicitly yourself. So your method should
> just be:
>
>     def __unicode__(self):
>         return unicode(self.grade)
>
> --
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.