for loop logic in template

2010-10-26 Thread jimgardener
hi
I have a model with 3 fields
class Employee(models.Model):
name=models.CharField(max_length=50)
home_address=models.TextField(blank=True)
change_filter=models.IntegerField()

I am creating a modelform using this class as model.
class EmployeeForm(ModelForm):
class Meta:
model=Employee

In my template,I want to give the IntegerField some special
treatment ..ie,I want to render it as input type="range" instead of a
text field.
I can do this like,
...

 Enter name:
 {{empform.name}}


{{empform.name.errors}}


 Enter address:
 {{empform.home_address}}


{{empform.home_address.errors}}



 select change filter value:
 


{{empform.change_filter.errors}}





Here ,I am using the same logic for the first two fields..
I want to render the change_filter using an input type="render"..
so I thought I can take care of this using a for loop.
{% for field in empform %}
{% ifequal field.name "change_filter" %}
  
   select change filter value:
   
  
{% else %}

{{ field.label_tag }}: {{ field }}

{% endifequal %}
{%if  field.errors %}
{{field.errors}}
{% endif %}
{% endfor %}


This gives the desired effect..But I am wondering if hardcoding the
field's name in the ifequal tag is the correct way.Can I check the
type of field instead?I am not sure how to do this..
Any advice would be nice..
thanks
jim



-- 
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 job needed

2010-10-26 Thread Venkatraman S
On Wed, Oct 27, 2010 at 1:04 AM, Swordfish  wrote:

> Hi everybody! I'm looking for a job deals with Django.
> Interesting in any kind of work: filling websites with images, texts,
> translations, testing.
> I'am Django newbie.Have previous experience with Plone.
>
>
http://djangogigs.com/

All the Best.

-V

-- 
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: Displaying Profile model in a form

2010-10-26 Thread Venkatraman S
On Wed, Oct 27, 2010 at 4:13 AM, christian.posta
wrote:

> I'm trying to display a form that has both the UserProfile fields and
> a select handful of the User fields.
> What's the best way to go about doing this? In the CreateUserForm that
> I'm creating, I have an inner Meta class with the 'model' = User, but
> of course that won't display the UserProfile fields. If I switch it to
> UserProfile, it won't display the User fields. I could re-create each
> of the UserProfile fields in the form, but that wouldn't be very DRY.
> On top of that, I'd have to handle the cascading commit and
> transactions myself if I manually handled the UserProfile and User
> objects separately. I'm hoping the framework has something and I just
> missed it?
>

Try having a look : from django.forms.models import inlineformset_factory
Or
http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/

Hope that helps.

-V
http://twitter.com/venkasub

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



Displaying Profile model in a form

2010-10-26 Thread christian.posta
I am relatively new to django. I've been reading the docs endlessly
and hacking to try to get something to work, but I'm hoping to not re-
create functionality that either exists or is part of the framework.

I have a class named UserProfile that I'd like to use to extend the
User object. I set it up properly within settings.py and have verified
from the shell that everything works.

I'm trying to display a form that has both the UserProfile fields and
a select handful of the User fields.
What's the best way to go about doing this? In the CreateUserForm that
I'm creating, I have an inner Meta class with the 'model' = User, but
of course that won't display the UserProfile fields. If I switch it to
UserProfile, it won't display the User fields. I could re-create each
of the UserProfile fields in the form, but that wouldn't be very DRY.
On top of that, I'd have to handle the cascading commit and
transactions myself if I manually handled the UserProfile and User
objects separately. I'm hoping the framework has something and I just
missed it?

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



djagios

2010-10-26 Thread Andrea Imparato
Hello to all,

I would like to add some nagios feature to my django app. I found this
project http://djagios.org/index.html but I see that is not supported
since 9 December 2009 :\. What do you think about it? Is it safe in
your opinion or can you suggest me other solutions?


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.



Re: Permission Denied when Trying to delete User

2010-10-26 Thread Shawn Milochik
Try going into the shell with 'manage.py shell,' import the User
model, and attempt to delete that user. See what happens and give us
the traceback if it fails and you still don't know why.

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 at 
http://groups.google.com/group/django-users?hl=en.



Django job needed

2010-10-26 Thread Swordfish
Hi everybody! I'm looking for a job deals with Django.
Interesting in any kind of work: filling websites with images, texts,
translations, testing.
I'am Django newbie.Have previous experience with Plone.

-- 
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: Query field across multiple django models

2010-10-26 Thread Ed
Do you have further detail on how this looks?  I was intending to use
forms.changed_data, but I would much rather get an automatic list of
changed fields by comparing the new submission to the initial state.
How do I compare the initial to the post within a pre_save function?


On Oct 26, 12:18 pm, bruno desthuilliers
 wrote:
> On 26 oct, 15:48, Ed  wrote:
>
> > I do like this a lot.  If I use post_save, is there a way to grab the
> > field that is altered?
>
> Nope, you have to use "pre_save" for this, load another (yet
> unmodified) copy of your model instance, and diff both.
>
> > I know the admin page seems to be able to
> > determine the changed field. . .
>
> ModelForms do keep a copy of the initial state so they can tell what
> went modified.

-- 
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 use tkinter widget in django

2010-10-26 Thread jimgardener
thanks elijah..that worked

how come id="id_user_entry" not enough?
regards
jim

On Oct 26, 11:54 pm, elijah rutschman  wrote:
> >   >       min="0"
> >       max="1000"
> >       step="2"
> >       value="6" id="id_user_entry"/>
>
> Try adding a name="user_entry" attribute to the input.

-- 
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Phlip


On Oct 26, 10:24 am, Phlip  wrote:
> > This sounds like what django-reversion[1] does :)
>
> > [1]:http://github.com/etianen/django-reversion#readme
>
> We have to cover the situation where some clients might still have
> rev(n-1), while some are up-to-date with rev(n). So we _probably_ need
> the history in the same table as the current version.
>
> I'm aware this is borderline "big requirements up front", but the
> answer turns out to be...
>
> class ThingManager(models.Manager):
>
>     def get_query_set(self):
>         qs = super(ThingManager, self).get_query_set()
>         max_pids = QuerySet(self.model, using=self._db)
>         max_pids =
> max_pids.values('name').annotate(Max('pid')).values('pid')

Uh, that was

         max_pids =
 max_pids.values('name').annotate(max_id=Max('pid')).values('pid')

If you don't name it you don't get the Max, even though nobody uses
the max_id in the resulting SELECT statement:

  SELECT "things".*,
FROM "things"
   WHERE ("things"."pid" IN (
   SELECT MAX(U0."pid") AS "max_id"
 FROM "things" U0
GROUP BY U0."name" ))


>         return qs.filter(pid__in=max_pids)
>
> Now we can write any ORM statement we can think of, and (if those
> lines continue to pass tests) then we only see the top horizon of the
> data. Unless we need to go deeper.
>
> Thanks, all!
>
> --
>   Phlip

-- 
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 the default widget to a field in a modelform

2010-10-26 Thread refreegrata
maybe I not explain correctly. For any modelForm the forms for a field
"ManytoMany"  are "select multiple". If I want to change this I must
to redefine the widget for that field in the declaration of the
"modelForm". This works correctly, I can transform the field from
"select multiple" to any "form" that I want. The problem appear when I
want to save the "form". Always the "form" is invalid because the
field type isn't a "select multiple". With a "select multiple" the
form can be saved, with other field types fail. Somebody have an idea?
Something that i can do in the view? Any opinion  can be helpful.

Thank for read

-- 
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 use tkinter widget in django

2010-10-26 Thread elijah rutschman
>         min="0"
>       max="1000"
>       step="2"
>       value="6" id="id_user_entry"/>

Try adding a name="user_entry" attribute to the input.

-- 
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 use tkinter widget in django

2010-10-26 Thread jimgardener
hi
thanks for the link.
I tried this,In firefox3.6.11 ,it is rendered as a text field
In chrome it shows a slider.

...

 select numerical value using slider:
 


{{myform.user_entry.errors}}

...
However,I am getting validation error upon processing the form
I put the field as an IntegerField in my model .I am not sure if that
is ok.

class MyModel(django.models.Model):
user_enrty=models.IntegerField()

class  MyModelForm(django.forms.ModelForm):
class Meta:
model=MyModel

In the view ,I checked for validity of form
...
form_data=get_form_data(request)
form=MyModelForm(form_data)
if request.method=='POST':
print 'request.POST=',request.POST
form_is_valid=form.is_valid()
print 'form is valid:',form_is_valid
if  form_is_valid:
newentry=form.save()
print 'newentry=',newentry
return redirect('home')
else:
print 'form is not valid'
...

Chrome complains that the slider field is required .The request.POST
is printed without the 'user_entry' key
I tried the same with firefox(which rendered the slider as textbox)
There also I get 'field is required error'

Any  idea how I can correct this? Why do the data in input
type="range" not coming in the request.POST querydict?

thanks
jim


On Oct 26, 7:11 pm, ringemup  wrote:
> Try the HTML5 .  On some current browsers, it'll
> just appear as a text field, although you can supplement it with
> javascript.  Moving forwards, as more browsers support HTML5 forms,
> it'll appear as a slider widget.  See [1].
>
> [1]http://diveintohtml5.org/forms.html#type-range

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



wsgi conf ignored after apache restart

2010-10-26 Thread Scot Hacker
We have a consistent mystery on one of our .edu sites I'm hoping  
someone can help solve.


If we restart apache on this shared host, the site reverts to a very  
old, non-Django version of itself. That is, an antique PHP-based  
version of  the site is served up, and the design changes to one that  
we haven't used for 1.5 years. IOTW, the wsgi configuration works  
perfectly  on a fresh server boot, but if apache is restarted, the  
wsgi configuration is ignored and apache tries to pull in an old PHP- 
based site instead.


The problem is NOT triggered by apachectl graceful, but it IS  
triggered by apachectl restart.


Once this happens, the ONLY fix we've been able to find is to  
physically restart the entire server (taking all the other sites down  
for a few minutes as we do). No amount of restarting apache or mysql  
will fix it.


WHM/cPanel server with mod_wsgi
Django 1.2.3, MySQL 5
Source in svn
There is NO Django caching enabled whatsoever
No *.pyc files
We don't use memcached (beefy server, moderate loads, we really don't  
need caching).
In WHM, there are no parked domains, add-on domains, or subdomains  
configured.


Has anyone ever experienced this or anything like it? I run a number  
of Django sites on a number of servers, and have never experienced  
anything like it. Thanks for a clue.



Thanks,

Scot

--
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Phlip
> Things.objects.filter(id__in=Things.objects.values('name').annotate(max_id= 
> Max('id')).values_list('max_id',
> flat=True))

I didn't do values_list because I guessed that the inner query would
run and produce an array, then the outer query would run.

My way, with values() on both sides of the aggregate(), MIGHT insert
the inner SELECT statement into the outer one, like our SQL examples.

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



Filtering Admin Inlines

2010-10-26 Thread Lllama
Hello all,

I've got an admin site that includes some inlines. These in turn
contain a ChoiceField. I'd like to filter the choices based on an
attribute of the parent model. Does anyone know if this is possible
and, if so, what hook I need to use?

I feel like I should be able to use formfield_for_dbfield, but it's
getting at that pesky parent that I'm unsure of.

Any help gratefully received,

Felix

-- 
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Alec Shaner
On Tue, Oct 26, 2010 at 12:40 PM, Phlip  wrote:
>
> So this statement correctly fetches only the latest items:
>
> SELECT a.* FROM things a WHERE a.pid in (select max(b.pid) from
> content_entity b group by b.name)
>
> Now I thought (from my allegedly copious experience with SQL) that I
> could do it with a join-on-self, but I can't seem to get the SQL
> syntax right. And if I did, I would then not know how to ORM-ize that
> syntax (and yes it must be ORM-ized, because this is indeed the core
> of the project, and everything has to see top-level horizons. Except
> auditors).
>

Regarding this query, I think you may be able to do this using
annotate. See http://docs.djangoproject.com/en/dev/topics/db/aggregation/#values

For example (and this probably sucks for performance):

Things.objects.filter(id__in=Things.objects.values('name').annotate(max_id=Max('id')).values_list('max_id',
flat=True))

This is just a self join example, but it could probably be rewritten
to use the two tables in your example.

-- 
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Phlip
> This sounds like what django-reversion[1] does :)
>
> [1]:http://github.com/etianen/django-reversion#readme

We have to cover the situation where some clients might still have
rev(n-1), while some are up-to-date with rev(n). So we _probably_ need
the history in the same table as the current version.

I'm aware this is borderline "big requirements up front", but the
answer turns out to be...

class ThingManager(models.Manager):

def get_query_set(self):
qs = super(ThingManager, self).get_query_set()
max_pids = QuerySet(self.model, using=self._db)
max_pids =
max_pids.values('name').annotate(Max('pid')).values('pid')
return qs.filter(pid__in=max_pids)

Now we can write any ORM statement we can think of, and (if those
lines continue to pass tests) then we only see the top horizon of the
data. Unless we need to go deeper.

Thanks, all!

--
  Phlip

-- 
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: Multiple database issue v1.2.3 - Django reading the wrong database

2010-10-26 Thread Stodge
Pasted misleading traceback, as I created the scene table in the
default database to verify this.

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
line 132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 336, in get
num = len(clone)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 81, in __len__
self._result_cache = list(self.iterator())
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 269, in iterator
for row in compiler.results_iter():
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/
compiler.py", line 672, in results_iter
for rows in self.execute_sql(MULTI):
  File "/usr/lib/python2.6/site-packages/django/db/models/sql/
compiler.py", line 727, in execute_sql
cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/util.py",
line 15, in execute
return self.cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/django/db/backends/
postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
DatabaseError: relation "scene" does not exist
LINE 1: ...le", "scene"."datasets", "scene"."transform" FROM "scene"
WH...


On Oct 26, 1:13 pm, Stodge  wrote:
> I have two PostgreSQL (postgresql_psycopg2) databases defined in my
> settings; default and scenes.
>
> If I perform a filter using the 'scenes' DB I get the expected
> results:
>
> Scene.objects.filter(name__contains='ME').using('scenes')
> [, ]
>
> If I perform a get(), Django seems to get completely confused and
> tries to read the data from the default database:
>
> Scene.objects.get(id=3).using('scenes')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
> line 132, in get
>     return self.get_query_set().get(*args, **kwargs)
>   File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 341, in get
>     % self.model._meta.object_name)
> DoesNotExist: Scene matching query does not exist.
>
> Anyone else seen this?
>
> 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.



Re: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Łukasz Rekucki
On 26 October 2010 19:05, Steve Holden  wrote:
> On 10/26/2010 12:40 PM, Phlip wrote:
>> Note that "isabelle_item" appears twice. We are following the auditing
>> rule "always write new records to change data - never edit previous
>> records". Someone edited isabelle_item's payload data (not shown), so
>> we add a new record without touching the existing record.
>
> I hope the auditors are only forcing you to do this with records that
> aren't referenced as part of relationships, otherwise your database is
> going to get hammered updating all the foreign keys.
>
> Wouldn't it make more sense (not that auditors will necessarily be
> persuaded by sensible arguments) to dump a copy of a row (plus possibly
> a timestamp field) to an archival table before update? This coild easily
> be done on a pre-save signal ...

This sounds like what django-reversion[1] does :)

[1]: http://github.com/etianen/django-reversion#readme

-- 
Łukasz Rekucki

-- 
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Phlip
> I hope the auditors are only forcing you to do this with records that
> aren't referenced as part of relationships, otherwise your database is
> going to get hammered updating all the foreign keys.

The design spec (which is ours, not any "CPA auditor's"), say to
duplicate the living crap out of them. Plz don't go there.

> Wouldn't it make more sense (not that auditors will necessarily be
> persuaded by sensible arguments) to dump a copy of a row (plus possibly
> a timestamp field) to an archival table before update? This coild easily
> be done on a pre-save signal ...

Maybe.

Now how do I do a "group by" on an aggregate? I'm down to this:

st=Student.objects.filter(marks__in=Student.objects.all().aggregate(Max('marks'),
group_by='name'))

Guess what? The "group_by" doesn't work, and Googling for "group by"
returns all kinds of useless newb crap. Just sayin...

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



Multiple database issue v1.2.3 - Django reading the wrong database

2010-10-26 Thread Stodge
I have two PostgreSQL (postgresql_psycopg2) databases defined in my
settings; default and scenes.

If I perform a filter using the 'scenes' DB I get the expected
results:

Scene.objects.filter(name__contains='ME').using('scenes')
[, ]

If I perform a get(), Django seems to get completely confused and
tries to read the data from the default database:


Scene.objects.get(id=3).using('scenes')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
line 132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
line 341, in get
% self.model._meta.object_name)
DoesNotExist: Scene matching query does not exist.

Anyone else seen this?

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.



Re: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Steve Holden
On 10/26/2010 12:40 PM, Phlip wrote:
> Note that "isabelle_item" appears twice. We are following the auditing
> rule "always write new records to change data - never edit previous
> records". Someone edited isabelle_item's payload data (not shown), so
> we add a new record without touching the existing record.

I hope the auditors are only forcing you to do this with records that
aren't referenced as part of relationships, otherwise your database is
going to get hammered updating all the foreign keys.

Wouldn't it make more sense (not that auditors will necessarily be
persuaded by sensible arguments) to dump a copy of a row (plus possibly
a timestamp field) to an archival table before update? This coild easily
be done on a pre-save signal ...

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
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 without template (no colors, no css, just simple html)

2010-10-26 Thread Giancarlo Razzolini

So I did the right thing... nice!

Giancarlo Razzolini
http://lock.razzolini.adm.br
Linux User 172199
Red Hat Certified Engineer no:804006389722501
Verify:https://www.redhat.com/certification/rhce/current/
Moleque Sem Conteudo Numero #002
OpenBSD 4.5
Ubuntu 9.04 Jaunty Jackalope
4386 2A6F FFD4 4D5F 5842  6EA0 7ABE BBAB 9C0E 6B85



Daniel Roseman wrote:

On Oct 26, 1:25 pm, Giancarlo Razzolini  wrote:
  

I had this same problem when hosting it with apache. I solved the
problem by creating a symbolic link inside my media folder pointing to
the admin site that is instaled with django. Something like this:

admin -> /usr/share/pyshared/django/contrib/admin/media/

Of course, this would only work in unix environments. I've tried to
solve it by tweaking with the settings.py file, but couldn't find a
solution. The link did the trick.

My regards,



There's no tweaking of settings.py that can somehow 'fix' this.
Setting up Apache to serve the files is the only correct thing to do,
whether that's by symlinking or whatever.
--
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: nl2br or equivalent to django

2010-10-26 Thread refreegrata
Thanks, is clearly explained in the documentation. I feel embarrassed
for do a post for something like this.

On 26 oct, 13:25, Daniel Roseman  wrote:
> On Oct 26, 5:02 pm, refreegrata  wrote:
>
> > Hello list, I have a newie question, are in django some function like
> > nl2br in the template to print data saved previously from a
> > "textarea"? because in my template all the lines are printed in the
> > same line.
>
> > P.D.: nl2br is PHP function to do this:
>
> > "a
> > b
> > c"
>
> > is tranformed in
> > "abc"
>
> > Thanks for read, and sorry for my poor english
>
> http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#linebreaks
> andhttp://docs.djangoproject.com/en/1.2/ref/templates/builtins/#linebrea...
> --
> 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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Phlip
Tom Evans wrote:

> Phlip, I'm going to try and make a non-stupid comment now :)

http://xkcd.com/386/

> If you already know precisely the query you want to use, and you can't
> coerce django's ORM to produce it, can you simply use Manager.raw()[1]
> to generate the result set you are after?

Because the point of an ORM is to distribute declarations of relations
among objects, so each object adds details to a query set, and the ORM
can build the final SELECT statements for each context.

So anyway, here's a table (hand-censored - it's a blue-sky project in
a hyper-competitive space):

> select * from things;
+-+-+
| pid | name|
+-+-+
|   6 | soca_2k7_user   |
|   7 | isabelle_item   |
|   8 | max_item|
|   9 | isabelle_item   |
+-+-+

Note that "isabelle_item" appears twice. We are following the auditing
rule "always write new records to change data - never edit previous
records". Someone edited isabelle_item's payload data (not shown), so
we add a new record without touching the existing record.

This implies that all normal database queries should only look at the
"top level horizon" of the database. (And this implies we must mix-and-
match such queries, and they can't all rely on the order_by('-pk')[0]
trick.)

So this statement correctly fetches only the latest items:

SELECT a.* FROM things a WHERE a.pid in (select max(b.pid) from
content_entity b group by b.name)

Now I thought (from my allegedly copious experience with SQL) that I
could do it with a join-on-self, but I can't seem to get the SQL
syntax right. And if I did, I would then not know how to ORM-ize that
syntax (and yes it must be ORM-ized, because this is indeed the core
of the project, and everything has to see top-level horizons. Except
auditors).

--
  Phlip
  http://zeekland.zeroplayer.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Access to field name in upload_to?

2010-10-26 Thread Scott Gould
> One idea would be to put 'fieldname' as the first parameter to the
> function, then use functools.partial [1] to create partial functions
> for each file field with the value set appropriately:
>
>         thumbnail_image = FileField(upload_to=partial(get_upload_path,
> 'thumbnail_image'))

Outstanding, thanks. I actually thought to myself "I need a decorator
type thing that I can pass a value with but still have it behave like
a callable" but didn't know about functools.partial.

-- 
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: nl2br or equivalent to django

2010-10-26 Thread Daniel Roseman
On Oct 26, 5:02 pm, refreegrata  wrote:
> Hello list, I have a newie question, are in django some function like
> nl2br in the template to print data saved previously from a
> "textarea"? because in my template all the lines are printed in the
> same line.
>
> P.D.: nl2br is PHP function to do this:
>
> "a
> b
> c"
>
> is tranformed in
> "abc"
>
> Thanks for read, and sorry for my poor english

http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#linebreaks
and
http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#linebreaksbr
--
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.



help with model definition

2010-10-26 Thread pixelcowboy
I have a question regarding the best way to conceptualize a model. I
have a tasks model, which I want to hook to a few different other
models: The model Project, the model Company and a few other undefined
models. The problem is that I want a particular instance of the task
to be pluggable to one and only one of those models, which I dont know
how I would achieve using 2 or more separate foreign keys. The only
idea I have is to use generic relationships, and unique them. Any
ideas?

-- 
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: Query field across multiple django models

2010-10-26 Thread bruno desthuilliers
On 26 oct, 15:48, Ed  wrote:
> I do like this a lot.  If I use post_save, is there a way to grab the
> field that is altered?

Nope, you have to use "pre_save" for this, load another (yet
unmodified) copy of your model instance, and diff both.

> I know the admin page seems to be able to
> determine the changed field. . .


ModelForms do keep a copy of the initial state so they can tell what
went modified.

-- 
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: Graphic and form in the same template

2010-10-26 Thread Waleria
I don't understand what you said.

Thanks

On 26 out, 12:19, Daniel Roseman  wrote:
> On Oct 26, 3:08 pm, Waleria  wrote:
>
> > I know that the execution of the function stops there, but i don't
> > know how do i resolve. I need to display the graphic generated and
> > just below the form.
>
> > Can you help me, please?
>
> > Thanks
>
> Well as far as I can tell, the generated graphic doesn't depend on the
> request or the form at all. So why does it need to be created in the
> same view as the form? It seems like you just need your template to
> contain a normal HTML image tag, whose `src` attribute is a URL that
> points to the gera_grafico function (or a wrapped version that returns
> the FigureCanvas).
> --
> 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.



nl2br or equivalent to django

2010-10-26 Thread refreegrata
Hello list, I have a newie question, are in django some function like
nl2br in the template to print data saved previously from a
"textarea"? because in my template all the lines are printed in the
same line.

P.D.: nl2br is PHP function to do this:

"a
b
c"

is tranformed in
"abc"

Thanks for read, and sorry for my poor english

-- 
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: Access to field name in upload_to?

2010-10-26 Thread Daniel Roseman
On Oct 26, 4:29 pm, Scott Gould  wrote:
> Hi folks,
>
> I've got all my file uploads (that go to S3 as it happens, but I don't
> think that's overly important) taking their path from one upload_to
> delegate:
>
> def get_upload_path(instance, filename=None):
>         """
>         Defaults to appname/modelname/uuid.
>         """
>         return "%s/%s/%s" % (
>                 instance.__class__._meta.app_label,
>                 instance.__class__.__name__.lower(),
>                 instance.uuid)
>
> That's obviously predicated on a field called "uuid" on any model that
> uses this method for calculating the upload path. This works fine, but
> I now want to deploy the same system on models with multiple
> FieldFields. The way I'd like to extend this is by appending the field
> name onto the existing file structure:
>
> def get_upload_path(instance, filename=None):
>         return "%s/%s/%s/%s" % (
>                 instance.__class__._meta.app_label,
>                 instance.__class__.__name__.lower(),
>                 instance.uuid,
>                 APPROPRIATE_FIELD_NAME_HERE)
>
> Which should result in something like "myapp/mymodel//
> pdf_file" and "myapp/mymodel//thumbnail_image" given this
> model:
>
> class MyModel(models.Model):
>         pdf_file = FileField(upload_to=get_upload_path)
>         thumbnail_image = FileField(upload_to=get_upload_path)
>
> Any ideas how I can get that field name inside the upload_to function?
> Thanks!

One idea would be to put 'fieldname' as the first parameter to the
function, then use functools.partial [1] to create partial functions
for each file field with the value set appropriately:

        thumbnail_image = FileField(upload_to=partial(get_upload_path,
'thumbnail_image'))

[1]: http://docs.python.org/library/functools.html#functools.partial
--
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.



'str' object not callable

2010-10-26 Thread John Yeukhon Wong
This is part of my views

[[[code]]]  from mysite.views

def site_root(request):
return HttpResponse("This is the site root")
def hello(request):
return HttpResponse("Hello World")

[[endcode]]

My URLConf
[[code]]
from django.conf.urls.defaults import *

urlpatterns = patterns('mysite.views',
(r'^$', 'site_root'),
(r'^hello/$', 'hello'),
(r'^now/plus/(\d{1,2})/$',
'offset_time'),
)
[[/code]]

I am actually following the book "The Definitive Guide to Django (2)""
chapter 8 advacne URLConf and views.
The sample code was

[[code]]
from django.conf.urls.defaults import *
urlpatterns = patterns('mysite.views',
(r'^hello/$', 'hello'),
(r'^time/$', 'current_datetime'),
(r'^time/plus/(\d{1,2})/$', 'hours_ahead'),
)
[[//code]]

What is wrong with my url?
I am calling the root right now, localhost, and root view is the first
one to be called. That gives me the error, and thus any url thereafter
gives the same error.

Any input is appreicated. 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.



Access to field name in upload_to?

2010-10-26 Thread Scott Gould
Hi folks,

I've got all my file uploads (that go to S3 as it happens, but I don't
think that's overly important) taking their path from one upload_to
delegate:

def get_upload_path(instance, filename=None):
"""
Defaults to appname/modelname/uuid.
"""
return "%s/%s/%s" % (
instance.__class__._meta.app_label,
instance.__class__.__name__.lower(),
instance.uuid)

That's obviously predicated on a field called "uuid" on any model that
uses this method for calculating the upload path. This works fine, but
I now want to deploy the same system on models with multiple
FieldFields. The way I'd like to extend this is by appending the field
name onto the existing file structure:

def get_upload_path(instance, filename=None):
return "%s/%s/%s/%s" % (
instance.__class__._meta.app_label,
instance.__class__.__name__.lower(),
instance.uuid,
APPROPRIATE_FIELD_NAME_HERE)

Which should result in something like "myapp/mymodel//
pdf_file" and "myapp/mymodel//thumbnail_image" given this
model:

class MyModel(models.Model):
pdf_file = FileField(upload_to=get_upload_path)
thumbnail_image = FileField(upload_to=get_upload_path)

Any ideas how I can get that field name inside the upload_to function?
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.



Re: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Tom Evans
Phlip, I'm going to try and make a non-stupid comment now :)

If you already know precisely the query you want to use, and you can't
coerce django's ORM to produce it, can you simply use Manager.raw()[1]
to generate the result set you are after?

Eg,

Student.objects.raw(r'SELECT * FROM `student` WHERE mark=(select
max(mark) from student)')

Cheers

Tom

[1] http://docs.djangoproject.com/en/1.2/topics/db/sql/

On Tue, Oct 26, 2010 at 3:17 PM, Phlip  wrote:
>> st=Student.objects.filter(marks__in=Student.objects.all().aggregate(Max('ma 
>> rks')))
>
> Aha - a marks__in may point to an aggregate subquery.
>
> In conclusion, screw my SQL server's optimizer. It deserves to suffer!
>
> (I can't seem to find a self-join to do what I need either...)
>
> --
> 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: Query field across multiple django models

2010-10-26 Thread Scott Gould
> Second, I'm not sure I understood the last part about getting the
> field within each model.

Sorry, I misread, thinking you were talking about having different
parameters of each model being responsible for what counted as
"latest". Bruno's solution looks good to me.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Graphic and form in the same template

2010-10-26 Thread Daniel Roseman
On Oct 26, 3:08 pm, Waleria  wrote:
> I know that the execution of the function stops there, but i don't
> know how do i resolve. I need to display the graphic generated and
> just below the form.
>
> Can you help me, please?
>
> Thanks

Well as far as I can tell, the generated graphic doesn't depend on the
request or the form at all. So why does it need to be created in the
same view as the form? It seems like you just need your template to
contain a normal HTML image tag, whose `src` attribute is a URL that
points to the gera_grafico function (or a wrapped version that returns
the FigureCanvas).
--
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Phlip
> st=Student.objects.filter(marks__in=Student.objects.all().aggregate(Max('ma 
> rks')))

Aha - a marks__in may point to an aggregate subquery.

In conclusion, screw my SQL server's optimizer. It deserves to suffer!

(I can't seem to find a self-join to do what I need either...)

-- 
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 use tkinter widget in django

2010-10-26 Thread ringemup
Try the HTML5 .  On some current browsers, it'll
just appear as a text field, although you can supplement it with
javascript.  Moving forwards, as more browsers support HTML5 forms,
it'll appear as a slider widget.  See [1].

[1]http://diveintohtml5.org/forms.html#type-range


On Oct 26, 7:17 am, jimgardener  wrote:
> is it possible to use the sliderlike Scale widget from tkinter in
> django?I am coding a web app where I need to get a numerical value
> entered by the user.I thought ,instead of asking the user to enter a
> value in a textfield ,I would provide a slider which he can move
> between the minimum and maximum values.
> Originally I designed the model and form like this
>
> class MyModel(django.models.Model):
>     user_enrty=models.IntegerField()
>
> class  MyModelForm(django.forms.ModelForm):
>     class Meta:
>         model=MyModel
>
> In tkinter ,I can create a scale widget like
> master = Tk()
> w = Scale(master, from_=0, to=100)
> w.pack()
> and get the current position using w.get()
>
> How can I use this in django?Can I directly put the tkinter widget in
> my model like ,
> class MyModel(django.models.Model):
>     user_enrty=tkinter.Scale(...)
>
> Any help would be greatly appreciated
> thanks
> jim

-- 
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: Graphic and form in the same template

2010-10-26 Thread Waleria
I know that the execution of the function stops there, but i don't
know how do i resolve. I need to display the graphic generated and
just below the form.

Can you help me, please?

Thanks

On 26 out, 11:42, Daniel Roseman  wrote:
> On Oct 26, 2:17 pm, Waleria  wrote:
>
> > Hi all,
>
> > I have this code:http://pastebin.com/Ra1G7twn
>
> > I need to display the graphic generated and just below the form, now
> > the code only display the form. The image of graphic isn't displayed.
>
> > What could it be?
>
> > How do i resolve?
>
> > Thanks
>
> I don't understand what you are expecting to happen here. Line 22 is a
> return statement, and so execution of the function stops there.
> There's no way to get to the code in lines 29-34.
> --
> 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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Phlip
On Oct 26, 2:42 am, Tom Evans  wrote:

> I'm curious, why can't I talk you into
> Student.objects.all().order_by('-score')[0] ?
>
> It is clearly a superior query :/

> >> ( BTW please don't try to talk me out of it; I've been doing SQL since
> >> 1989 and am fully aware of all the alternatives there. C-; )

Hmm. Maybe I ought to start another thread where I describe the actual
problem, in nauseatingly elaborate detail. In this thread I just want
to learn any sick notations available there.

Other mails not processed yet. BRB!

-- 
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: Query field across multiple django models

2010-10-26 Thread Ed
I do like this a lot.  If I use post_save, is there a way to grab the
field that is altered?  I know the admin page seems to be able to
determine the changed field. . .

On Oct 26, 9:41 am, bruno desthuilliers
 wrote:
> On 26 oct, 13:25, Ed  wrote:
>
>
>
>
>
>
>
>
>
> > I want to create a "What's New" section that lists all of the database
> > changes in the last day. I've added an "updated" field to my models:
>
> > class Film(models.Model):
> >    .
> >    .
> >    .
> >    updated = models.DateTimeField(auto_now=True)
>
> > class Actor(models.Model):
> >    .
> >    .
> >    .
> >    updated = models.DateTimeField(auto_now=True)
>
> > Now I want to query across all of my models to get a date-sorted list
> > of the most recent changes. How do I query the "updated" field across
> > multiple models? Is this the most efficient way to achieve the primary
> > purpose?
>
> > What if I wanted to be more specific and list the actual field that
> > was altered within each model?
>
> Another solution is to have a specific "LastChange" model with a
> GenericForeignKey on your other models (the ones you want to monitor)
> and hook into the appropriate signal (models.signals.pre_save or
> models.signals.post_save look like a good start) to feed it with
> relevant data.
>
> The neat points are that:
>
> 1/ you can monitor just any model, without having to add special
> fields
> 2/ you only have one table to query to build your "what's new" section
> (depending on what infos you store in LastChange, you may not need to
> get at the changed object at all)
>
> HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Query field across multiple django models

2010-10-26 Thread Ed
If there is no simpler way to do this, then I'm fine with this
method.  2 questions though.

Is there a concern about the size of the query required for the
big_honking_list?  I would probably be pulling a much larger dataset
than I need and can only truncate it after it's sorted by date.

Second, I'm not sure I understood the last part about getting the
field within each model.  So my example:

class Film(models.Model):
   title = models.CharField(max_length=50, unique = True)
   year = models.IntegerField()
   length = models.IntegerField()
   updated = models.DateTimeField(auto_now=True)

If I updated length, saved, then updated year, then saved, could I get
a list that would say:

What's new
Film Length: updated 2:15am
Film Year: updated 2:20 am
etc.

On Oct 26, 7:44 am, Scott Gould  wrote:
> Maybe -- in fact, almost certainly not -- the best way, but this is
> how I do that kind of thing:
>
>         a_queryset = ModelA.objects.all()
>         another_queryset = ModelB.objects.filter.(by_something=True)
>         yet_another_queryset =
> ModelC.objects.exclude(by_something_else=False)
>
>         from itertools import chain
>         big_honking_list = list(chain(a_queryset, another_queryset,
> yet_another_queryset))
>         big_honking_list.sort(key=lambda x: x.updated)
>         big_honking_list.reverse()
>
> As to your last question, that is easy if you're doing a list.sort()
> -- just expose a method on each model that returns a sortable value
> that is consistent across all the models. (Or write a dedicated
> function to use instead of the lambda above, whichever makes more
> sense.)
>
> On Oct 26, 7:25 am, Ed  wrote:
>
>
>
>
>
>
>
> > I want to create a "What's New" section that lists all of the database
> > changes in the last day. I've added an "updated" field to my models:
>
> > class Film(models.Model):
> >    .
> >    .
> >    .
> >    updated = models.DateTimeField(auto_now=True)
>
> > class Actor(models.Model):
> >    .
> >    .
> >    .
> >    updated = models.DateTimeField(auto_now=True)
>
> > Now I want to query across all of my models to get a date-sorted list
> > of the most recent changes. How do I query the "updated" field across
> > multiple models? Is this the most efficient way to achieve the primary
> > purpose?
>
> > What if I wanted to be more specific and list the actual field that
> > was altered within each model?

-- 
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: Graphic and form in the same template

2010-10-26 Thread Daniel Roseman
On Oct 26, 2:17 pm, Waleria  wrote:
> Hi all,
>
> I have this code:http://pastebin.com/Ra1G7twn
>
> I need to display the graphic generated and just below the form, now
> the code only display the form. The image of graphic isn't displayed.
>
> What could it be?
>
> How do i resolve?
>
> Thanks

I don't understand what you are expecting to happen here. Line 22 is a
return statement, and so execution of the function stops there.
There's no way to get to the code in lines 29-34.
--
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: Query field across multiple django models

2010-10-26 Thread bruno desthuilliers
On 26 oct, 13:25, Ed  wrote:
> I want to create a "What's New" section that lists all of the database
> changes in the last day. I've added an "updated" field to my models:
>
> class Film(models.Model):
>    .
>    .
>    .
>    updated = models.DateTimeField(auto_now=True)
>
> class Actor(models.Model):
>    .
>    .
>    .
>    updated = models.DateTimeField(auto_now=True)
>
> Now I want to query across all of my models to get a date-sorted list
> of the most recent changes. How do I query the "updated" field across
> multiple models? Is this the most efficient way to achieve the primary
> purpose?
>
> What if I wanted to be more specific and list the actual field that
> was altered within each model?

Another solution is to have a specific "LastChange" model with a
GenericForeignKey on your other models (the ones you want to monitor)
and hook into the appropriate signal (models.signals.pre_save or
models.signals.post_save look like a good start) to feed it with
relevant data.

The neat points are that:

1/ you can monitor just any model, without having to add special
fields
2/ you only have one table to query to build your "what's new" section
(depending on what infos you store in LastChange, you may not need to
get at the changed object at all)

HTH

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



possible bug with onetoone relationship and psycopg2

2010-10-26 Thread sircco
Looking for someone to check into this, before i submit
problem is with __isnull=False handling

backend is psycopg2

tables:

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

class SampleTest(models.Model):
person = models.OneToOneField(Person,primary_key=True)
entry_date = models.DateField()

from django.db import connection

Person.objects.filter(sampletest__isnull=True)[0]
print connection.queries  [SQL OK]

Person.objects.filter(sampletest__isnull=False)[0]
print connection.queries

now note that person table doesnt even try to join sampletest
table ...

Person.objects.filter(sampletest__isnull=False)[0].sampletest
throws DoesNotExist exception

-- 
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: choosing queryset

2010-10-26 Thread vamsy krishna
That's it! Thanks for pointing me in the right direction. Also my
apologies for posting on the other forum. I did not know i wasn't
supposed to do that.

And thanks DR for your response. I've sorted it out now.

On Oct 26, 5:42 pm, Jirka Vejrazka  wrote:
> > I've two modules called plan and income and both have a class called
> > Income in their respective models. Now if I do user.income_set, it is
> > accessing the income set under plan. How do I alter it to access
> > income.income? Any ideas?
>
> Hi,
>
>   have you had a chance to check out related_name in the
> documentation? It does define "how should the other model call me".
> Seehttp://docs.djangoproject.com/en/dev/ref/models/fields/
>
>   HTH
>
>     Jirka

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



Graphic and form in the same template

2010-10-26 Thread Waleria
Hi all,

I have this code: http://pastebin.com/Ra1G7twn

I need to display the graphic generated and just below the form, now
the code only display the form. The image of graphic isn't displayed.

What could it be?

How do i resolve?

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.



Re: Admin without template (no colors, no css, just simple html)

2010-10-26 Thread Daniel Roseman
On Oct 26, 1:25 pm, Giancarlo Razzolini  wrote:
> I had this same problem when hosting it with apache. I solved the
> problem by creating a symbolic link inside my media folder pointing to
> the admin site that is instaled with django. Something like this:
>
> admin -> /usr/share/pyshared/django/contrib/admin/media/
>
> Of course, this would only work in unix environments. I've tried to
> solve it by tweaking with the settings.py file, but couldn't find a
> solution. The link did the trick.
>
> My regards,

There's no tweaking of settings.py that can somehow 'fix' this.
Setting up Apache to serve the files is the only correct thing to do,
whether that's by symlinking or whatever.
--
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: What does an ideal django workflow setup look like?

2010-10-26 Thread Celso González
On Fri, Oct 22, 2010 at 08:02:56AM -0700, Ken wrote:

Hi

> I understand there are many different ways and products to use to
> setup a great workflow for developing in django, but would like to
> hear how you or your startup team (or corporate dev group) does it.
> Specifics would be amazing, as I need a little hand holding, i.e.
> please cover anything and everything that I should know in order to
> develop efficiently, robustly, and eventually collaboratively.

There are common ideas like +1 South, local_settings.py, vcs and
helper scripts like fabric

> Basically, please explain it in a way that a layman can follow the
> steps and setup a workflow without pulling his hair out. =P

ok, my system

Every project has its own virtual enviroment

-virtualenv
--bin
--include
--lib
--requirements.txt
--myproject
---apps
...
---static
---templates


*All the structure and contents goes into git or vcs of choice
*pip freeze > requirements.txt and pip install -r requirements.txt
to handle the external soft installed
*in .gitignore I override bin, include, lib, src directories

Just using git and virtualenv im able to create the same enviroment
quickly in several machines (dev, testing, production)

Still working on the database exports

-- 
Celso González (PerroVerd)
http://mitago.net

-- 
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 use tkinter widget in django

2010-10-26 Thread Steve Holden
On 10/26/2010 8:50 AM, jimgardener wrote:
> thanks for the replies..
> I am wondering if javascript is the only alternative if I want to use
> such a custom widget.
> If anyone knows about any such python widget please tell me..
> regards
> jim
> 
Jim:

The reason you can forget using Python is that Python isn't available on
the browser. You have to deliver content from Django that the user's
browser can execute, and that isn't likely to include Python in most cases.

  http://www.learnthenet.com/learn-about/how-the-web-works/

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
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 use tkinter widget in django

2010-10-26 Thread Jirka Vejrazka
> thanks for the replies..
> I am wondering if javascript is the only alternative if I want to use
> such a custom widget.
> If anyone knows about any such python widget please tell me..

  You might want to dig a bit into website design to understand how
JavaScript-based systems work. That would help you to understand why
you *cannot* use any Python widget for such task. (polite hint -
JavaScript runs in the browser and can be started from a HTML page
served by a server)

  Cheers

Jirka

-- 
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 use tkinter widget in django

2010-10-26 Thread jimgardener
thanks for the replies..
I am wondering if javascript is the only alternative if I want to use
such a custom widget.
If anyone knows about any such python widget please tell me..
regards
jim

-- 
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: choosing queryset

2010-10-26 Thread Daniel Roseman
On Oct 26, 1:29 pm, vamsy krishna  wrote:
> I've two modules called plan and income and both have a class called
> Income in their respective models. Now if I do user.income_set, it is
> accessing the income set under plan. How do I alter it to access
> income.income? Any ideas?
>
> Thanks in advance

Well, which is the one that has a relationship to User?

You could help yourself by showing some code here.
--
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: choosing queryset

2010-10-26 Thread Jirka Vejrazka
> I've two modules called plan and income and both have a class called
> Income in their respective models. Now if I do user.income_set, it is
> accessing the income set under plan. How do I alter it to access
> income.income? Any ideas?

Hi,

  have you had a chance to check out related_name in the
documentation? It does define "how should the other model call me".
See http://docs.djangoproject.com/en/dev/ref/models/fields/

  HTH

Jirka

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



choosing queryset

2010-10-26 Thread vamsy krishna
I've two modules called plan and income and both have a class called
Income in their respective models. Now if I do user.income_set, it is
accessing the income set under plan. How do I alter it to access
income.income? Any ideas?

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: Admin without template (no colors, no css, just simple html)

2010-10-26 Thread Giancarlo Razzolini
I had this same problem when hosting it with apache. I solved the 
problem by creating a symbolic link inside my media folder pointing to 
the admin site that is instaled with django. Something like this:


admin -> /usr/share/pyshared/django/contrib/admin/media/

Of course, this would only work in unix environments. I've tried to 
solve it by tweaking with the settings.py file, but couldn't find a 
solution. The link did the trick.


My regards,

Giancarlo Razzolini
http://lock.razzolini.adm.br
Linux User 172199
Red Hat Certified Engineer no:804006389722501
Verify:https://www.redhat.com/certification/rhce/current/
Moleque Sem Conteudo Numero #002
OpenBSD 4.5
Ubuntu 9.04 Jaunty Jackalope
4386 2A6F FFD4 4D5F 5842  6EA0 7ABE BBAB 9C0E 6B85



rebus_ wrote:

On 26 October 2010 06:48, marcoarreguin  wrote:
  

I'm starting with Django and I have a bluehost, yesterday I have been
installing all the stuff, I found a tutorial about how to install
django in bluehost, so I'm using fcgi.

My problem is that when I uncomment the necesary things to run my
admin, it runs, but it hasn't a layout like the images in the
tutoriales, like the login box is centered and have a blue rectangle,
I just have a little login in the left part of my screen without
colors and that stuff, and when I login, it happens the same I can see
my groups and all stuff but without format. ¿Do you know why is happen
this to me?

A hug, and I'm glad to be part of the community.

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





Check your ADMIN_MEDIA_PREFIX setting, the url it defines should serve
static media content by a web server, yours is probably been handled
by Django and thus not serving any static files (such as css)

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/;, "/media/".
ADMIN_MEDIA_PREFIX = '/admin-media/'

  


--
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 use tkinter widget in django

2010-10-26 Thread Nelson Saraiva
hi,
do this with JavaScript.





2010/10/26 jimgardener 

> is it possible to use the sliderlike Scale widget from tkinter in
> django?I am coding a web app where I need to get a numerical value
> entered by the user.I thought ,instead of asking the user to enter a
> value in a textfield ,I would provide a slider which he can move
> between the minimum and maximum values.
> Originally I designed the model and form like this
>
> class MyModel(django.models.Model):
>user_enrty=models.IntegerField()
>
> class  MyModelForm(django.forms.ModelForm):
>class Meta:
>model=MyModel
>
> In tkinter ,I can create a scale widget like
> master = Tk()
> w = Scale(master, from_=0, to=100)
> w.pack()
> and get the current position using w.get()
>
> How can I use this in django?Can I directly put the tkinter widget in
> my model like ,
> class MyModel(django.models.Model):
>user_enrty=tkinter.Scale(...)
>
> Any help would be greatly appreciated
> thanks
> jim
>
>
>
>
> --
> 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.
>
>


-- 
Nelson Saraiva.
-- -- -- -- -- -- -- --
""" Men are from Mars. Women are from Venus. Computers are from hell. "”"

-- 
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: (sem Assunto) Sorry... Django Setup Problem

2010-10-26 Thread Nelson Saraiva
you think this problem is the Django_countries?

I expected it to be in PostgreSQL.

I'll check the versions now!

Thanks



2010/10/26 Venkatraman S 

>
> On Tue, Oct 26, 2010 at 5:28 PM, Nelson Saraiva wrote:
>
>> *
>>  File
>> "C:\Python25\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py",
>> line 121,
>>  in _cursorraise ImproperlyConfigured("You need to specify NAME in
>> your Django settings file.")
>>
>> django.core.exceptions.ImproperlyConfigured: You need to specify NAME in
>> your Django settings file.*
>>
>> Can someone please help me?
>>
>
>
> Welcome to this list :)
>
> I am expecting that this is a collision of the django versions - did you
> check the version of the django that is to be used for Massive-Coupon and
> that to be used by django-countries?
>
> -V-
> http://twitter.com/venkasub
>
>  --
> 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.
>



-- 
Nelson Saraiva.
-- -- -- -- -- -- -- --
""" Men are from Mars. Women are from Venus. Computers are from hell. "”"

-- 
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 use tkinter widget in django

2010-10-26 Thread Steve Holden
On 10/26/2010 7:17 AM, jimgardener wrote:
> is it possible to use the sliderlike Scale widget from tkinter in
> django?I am coding a web app where I need to get a numerical value
> entered by the user.I thought ,instead of asking the user to enter a
> value in a textfield ,I would provide a slider which he can move
> between the minimum and maximum values.
> Originally I designed the model and form like this
> 
> class MyModel(django.models.Model):
> user_enrty=models.IntegerField()
> 
> class  MyModelForm(django.forms.ModelForm):
> class Meta:
> model=MyModel
> 
> In tkinter ,I can create a scale widget like
> master = Tk()
> w = Scale(master, from_=0, to=100)
> w.pack()
> and get the current position using w.get()
> 
> How can I use this in django?Can I directly put the tkinter widget in
> my model like ,
> class MyModel(django.models.Model):
> user_enrty=tkinter.Scale(...)
> 
Unfortunately you cannot do this. Tkinter assumes direct control of the
desktop, whereas Django is a web system that must use HTML (or similar)
to deliver markup to the user's desktop using HTTP. Tkinter just isn't a
web technology.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

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

2010-10-26 Thread Venkatraman S
On Tue, Oct 26, 2010 at 5:28 PM, Nelson Saraiva  wrote:

> *
>  File
> "C:\Python25\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py",
> line 121,
>  in _cursorraise ImproperlyConfigured("You need to specify NAME in your
> Django settings file.")
>
> django.core.exceptions.ImproperlyConfigured: You need to specify NAME in
> your Django settings file.*
>
> Can someone please help me?
>


Welcome to this list :)

I am expecting that this is a collision of the django versions - did you
check the version of the django that is to be used for Massive-Coupon and
that to be used by django-countries?

-V-
http://twitter.com/venkasub

-- 
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: What does an ideal django workflow setup look like?

2010-10-26 Thread David De La Harpe Golden
On 25/10/10 19:04, Jumpfroggy wrote:


> - +1 on using "settings.py" and "local_settings.py".  The problem with
> keeping local settings files in the VCS is when you have multiple
> servers with different settings.  You could store each file as
> local_settings_test_server.py and so on. 


We use a proj.settings along the lines of:

from proj.common_settings import *
import imp
imp.load_source('proj_local_settings', '/etc/proj/settings.py')
from proj_local_settings import *

to keep our host-specific settings outside VCS on each host.  A range of
more complex schemes are possible, of course.




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



[no subject]

2010-10-26 Thread Nelson Saraiva
Hi,
I'm new here in the List and  Django (i'm a intermediate python programmer),
i'm from Brazil.
one know
I'm trying to install a group buying system here in my machine called
Massive-Coupon, anyone know?

After you install many dependencies(Photologue, PyFacebook,
SocialRegistration,...), arose a problema.

One of the dependencies (Django Countries) don't have setup.py, in the
install.txt file said tha a i have to copy the folder "countries" to my site
folder and them run syncdb (python manage.py syncdb).

I have PostgreSQL and the module  psycopg2 installed on my machine, but see
the error that appears.

*.
.
.*
*
 File
"C:\Python25\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py",
line 121,
 in _cursorraise ImproperlyConfigured("You need to specify NAME in your
Django settings file.")

django.core.exceptions.ImproperlyConfigured: You need to specify NAME in
your Django settings file.*

I did not understand this message.
Digite um texto ou endereço de um site ou traduza um
documento.
Cancelar 

Can someone please help me?

Thanks!


-- 
Nelson Saraiva.
-- -- -- -- -- -- -- --
""" Men are from Mars. Women are from Venus. Computers are from hell. "”"

-- 
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: moving from Postgres to MySQL

2010-10-26 Thread David De La Harpe Golden
On 22/10/10 17:34, Kevin Monceaux wrote:

> I think the OP was referring to mysqldump's --compatible option which
> one could use, for example, as mysqldump --compatible=postgresql ...

Doesn't Work, btw. (really doesn't help much, at least in my experience
- you just end up with dump that's neither mysql nor postgresql
compatible).  If you do go the text dump conversion route (which I don't
recommend in the first place!), you're better off using mysqldump to
output a mysql dialect dump that can then be munged more comprehensively
into postgresql dialect by a third party tool e.g.
http://pgfoundry.org/projects/mysql2pgsql/



-- 
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: Query field across multiple django models

2010-10-26 Thread Scott Gould
Maybe -- in fact, almost certainly not -- the best way, but this is
how I do that kind of thing:

a_queryset = ModelA.objects.all()
another_queryset = ModelB.objects.filter.(by_something=True)
yet_another_queryset =
ModelC.objects.exclude(by_something_else=False)

from itertools import chain
big_honking_list = list(chain(a_queryset, another_queryset,
yet_another_queryset))
big_honking_list.sort(key=lambda x: x.updated)
big_honking_list.reverse()

As to your last question, that is easy if you're doing a list.sort()
-- just expose a method on each model that returns a sortable value
that is consistent across all the models. (Or write a dedicated
function to use instead of the lambda above, whichever makes more
sense.)

On Oct 26, 7:25 am, Ed  wrote:
> I want to create a "What's New" section that lists all of the database
> changes in the last day. I've added an "updated" field to my models:
>
> class Film(models.Model):
>    .
>    .
>    .
>    updated = models.DateTimeField(auto_now=True)
>
> class Actor(models.Model):
>    .
>    .
>    .
>    updated = models.DateTimeField(auto_now=True)
>
> Now I want to query across all of my models to get a date-sorted list
> of the most recent changes. How do I query the "updated" field across
> multiple models? Is this the most efficient way to achieve the primary
> purpose?
>
> What if I wanted to be more specific and list the actual field that
> was altered within each model?

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



Query field across multiple django models

2010-10-26 Thread Ed
I want to create a "What's New" section that lists all of the database
changes in the last day. I've added an "updated" field to my models:

class Film(models.Model):
   .
   .
   .
   updated = models.DateTimeField(auto_now=True)

class Actor(models.Model):
   .
   .
   .
   updated = models.DateTimeField(auto_now=True)

Now I want to query across all of my models to get a date-sorted list
of the most recent changes. How do I query the "updated" field across
multiple models? Is this the most efficient way to achieve the primary
purpose?

What if I wanted to be more specific and list the actual field that
was altered within each model?

-- 
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 use tkinter widget in django

2010-10-26 Thread jimgardener
is it possible to use the sliderlike Scale widget from tkinter in
django?I am coding a web app where I need to get a numerical value
entered by the user.I thought ,instead of asking the user to enter a
value in a textfield ,I would provide a slider which he can move
between the minimum and maximum values.
Originally I designed the model and form like this

class MyModel(django.models.Model):
user_enrty=models.IntegerField()

class  MyModelForm(django.forms.ModelForm):
class Meta:
model=MyModel

In tkinter ,I can create a scale widget like
master = Tk()
w = Scale(master, from_=0, to=100)
w.pack()
and get the current position using w.get()

How can I use this in django?Can I directly put the tkinter widget in
my model like ,
class MyModel(django.models.Model):
user_enrty=tkinter.Scale(...)

Any help would be greatly appreciated
thanks
jim




-- 
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: What does an ideal django workflow setup look like?

2010-10-26 Thread Brian Bouterse
I can't encourage it *enough*.  This was writen hastily, thanks for the
close read.

Brian

On Tue, Oct 26, 2010 at 1:01 AM, Kenneth Gonsalves wrote:

> On Mon, 2010-10-25 at 16:06 -0400, Brian Bouterse wrote:
> > I really can't encourage the use of Hudson  (or
> > something like it).
>
> 'cant encourage'? or 'can encourage'?
> --
> regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS at AU-KBC
>
> --
> 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.
>
>


-- 
Brian Bouterse
ITng Services

-- 
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 WEB SERVICE works?

2010-10-26 Thread girish shabadimath
sorry friends, ignore this

On Tue, Oct 26, 2010 at 4:31 PM, Tom Evans  wrote:

> Bad netiquette.
>
> Please don't send unsolicited attachments to mailing lists. If it is
> really that riveting, provide a link.
>
> On Tue, Oct 26, 2010 at 11:55 AM, girish shabadimath
>  wrote:
> >
> > Hi friends,
> > i found this ppt interesting, specially the diagram which made me to
> > understand WS better,,
> > hope it may help u too.
> > --
> > Girish M S
> >
> > --
> > 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.
>
>


-- 
Girish M S

-- 
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 WEB SERVICE works?

2010-10-26 Thread Tom Evans
Bad netiquette.

Please don't send unsolicited attachments to mailing lists. If it is
really that riveting, provide a link.

On Tue, Oct 26, 2010 at 11:55 AM, girish shabadimath
 wrote:
>
> Hi friends,
> i found this ppt interesting, specially the diagram which made me to
> understand WS better,,
> hope it may help u too.
> --
> Girish M S
>
> --
> 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: Admin without template (no colors, no css, just simple html)

2010-10-26 Thread rebus_
On 26 October 2010 06:48, marcoarreguin  wrote:
> I'm starting with Django and I have a bluehost, yesterday I have been
> installing all the stuff, I found a tutorial about how to install
> django in bluehost, so I'm using fcgi.
>
> My problem is that when I uncomment the necesary things to run my
> admin, it runs, but it hasn't a layout like the images in the
> tutoriales, like the login box is centered and have a blue rectangle,
> I just have a little login in the left part of my screen without
> colors and that stuff, and when I login, it happens the same I can see
> my groups and all stuff but without format. ¿Do you know why is happen
> this to me?
>
> A hug, and I'm glad to be part of the community.
>
> --
> 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.
>
>

Check your ADMIN_MEDIA_PREFIX setting, the url it defines should serve
static media content by a web server, yours is probably been handled
by Django and thus not serving any static files (such as css)

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/;, "/media/".
ADMIN_MEDIA_PREFIX = '/admin-media/'

-- 
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 page cms get_absolute_url return an empty strings andURL issues.

2010-10-26 Thread tricks...@googlemail.com
Sorted. The get absolute url had not been set and the ordering of urls
was incorrect.

-- 
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: Unable to filter a query on >1 ManyToMany relationships

2010-10-26 Thread Tom Evans
On Mon, Oct 25, 2010 at 6:30 PM, Jumpfroggy  wrote:
>
> I have a class like this:
>
> class Node:
>    name = models.CharField()
>    parents = models.ManyToManyField('self', symmetrical=False,
> related_name='child_nodes', null=True, blank=True)
>
> This allows a basic parent(s)/children hierarchy.  A node can have >=
> 0 parents.  A parent can have >= 0 children.
>
> Say I have these nodes:
>
> A - parent node
> B - parent node
> C - child of both A & B
>
> So I can do this:
>
>    Node.objects.filter(name='C')
>    > returns ['C' node].
>
>    Node.objects.filter(name='C', parents__name='A')
>    > returns ['C' node].
>
>    Node.objects.filter(name='C', parents__name='B')
>    > returns ['C' node].
>
>    Node.objects.filter(Q(name='C'), Q(parents__name='A'))
>    > returns ['C' node].
>
>    Node.objects.filter(Q(name='C'), Q(parents__name='B'))
>    > returns ['C' node].
>
>    Node.objects.filter(Q(name='C'), Q(parents__name='A'),
> Q(parents__name='B'))
>    > returns []
>
>    Node.objects.filter(Q(name='C') & Q(parents__name='A') &
> Q(parents__name='B'))
>    > returns []
>
>    Node.objects.filter(Q(parents__name='A'), Q(parents__name='B'))
>    > returns []
>
>
> Why do those last two return an empty set?  I can even do this:
>
>    Node.objects.filter(Q(name='C'),
> Q(parents__name='A')).filter(Q(parents__name='B'))
>    > returns ['C' node].
>
> That works.  But filtering on two parents (AND, not OR... I want the
> child nodes of both parents) returns the empty set.  It doesn't make
> sense to me why using two separate filters would work, but combining
> them into one statement gives different results.
>
> Anyone have an idea about this?  Is this a bug in the django query
> system, or am I looking at this wrong?  Thanks.
>

You're looking at it wrong. When you put multiple filter specs into
one filter call for a m2m join, what you are actually doing is adding
extra conditions to the m2m join.

So this one:

Node.objects.filter(Q(parents__name='A'), Q(parents__name='B'))

This is looking for a single node who has a single parent whose name
is both 'A' and 'B' - unlikely!

And this one:

Node.objects.filter(Q(parents__name='A')).filter(Q(parents__name='B'))

This is looking for a node which has a parent with name A, and a
parent with name B.

This is all clearly documented, see here:

http://docs.djangoproject.com/en/1.2/topics/db/queries/#spanning-multi-valued-relationships

Cheers

Tom

-- 
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 without template (no colors, no css, just simple html)

2010-10-26 Thread marcoarreguin
I'm starting with Django and I have a bluehost, yesterday I have been
installing all the stuff, I found a tutorial about how to install
django in bluehost, so I'm using fcgi.

My problem is that when I uncomment the necesary things to run my
admin, it runs, but it hasn't a layout like the images in the
tutoriales, like the login box is centered and have a blue rectangle,
I just have a little login in the left part of my screen without
colors and that stuff, and when I login, it happens the same I can see
my groups and all stuff but without format. ¿Do you know why is happen
this to me?

A hug, and I'm glad to be part of the community.

-- 
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Tom Evans
Course there could be, I'm being dense :/

On Tue, Oct 26, 2010 at 10:55 AM, Piotr Kilczuk  wrote:
>
>
> 2010/10/26 Tom Evans 
>>
>> I'm curious, why can't I talk you into
>> Student.objects.all().order_by('-score')[0] ?
>>
>> It is clearly a superior query :/
>
> This would select only one row; there can possibly be multiple students with
> a top note.
>
> Am I right? :)
>
> Regards,
> Piotr
>
> --
> 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: What does an ideal django workflow setup look like?

2010-10-26 Thread Tom Evans
On Mon, Oct 25, 2010 at 7:04 PM, Jumpfroggy  wrote:
> This is such a great thread!  I'd love to see a wiki page detailing
> some good setup ideas.  It's such a leap forward from the nuts & bolts
> of "How do I install django" and "How do I run a complex query" to
> this... "How do I use django more effectively, end to end?"
>
> I agree - most of these tips will be generic to project dev &
> deployment, but it seems there are a few django specific ones.
>
> My thoughts...
>
> - Use VCS.  First step.  I use SVN, but others are probably better.
> Even if you're a solo dev, even for small projects, it's worth it.
>

Others are 'cooler'. I'm not sufficiently versed in git or mercurial
to comment on whether they can handle the structures I'll describe
below..

>
> - +1 on using "settings.py" and "local_settings.py".  The problem with
> keeping local settings files in the VCS is when you have multiple
> servers with different settings.  You could store each file as
> local_settings_test_server.py and so on.  Then you could have
> something like "settings_server_name.py" that's not in VCS, and it
> only has:
>
>    SERVER_NAME = 'prod'
>
> And in your settings.py:
>
>    import * from settings_server_name
>
>    if SERVER_NAME == 'prod':
>        import * from settings_prod_server
>    elif SERVER_NAME == 'test':
>        ...
>        etc
>

Bit clunky isn't it? Every time you add/remove an instance of the
project, you have to update settings.py.

This is how I structure my projects in the svn repository (hope you
can all see unicode line segments!):

sample_project
├── configurations
│   ├── development-requirements.pip
│   ├── production-requirements.pip
│   ├── settings_local-app01.py
│   ├── settings_local-app02.py
│   ├── settings_local-dev-app01.py
│   └── settings_local-dev-app02.py
├── deployments
│   ├── app01
│   │   ├── logs
│   │   └── scripts
│   ├── app02
│   │   ├── logs
│   │   └── scripts
│   ├── dev-app01
│   │   ├── logs
│   │   └── scripts
│   └── dev-app02
│   ├── logs
│   └── scripts
├── scripts
│   ├── bootstrap
│   └── project
└── src
├── releases
│   ├── 1.0
│   │   └── htdocs
│   ├── 1.1
│   │   └── htdocs
│   └── 1.2
│   └── htdocs
└── trunk
└── htdocs

Each deployed instance of the project gets a folder in
sample_project/deployments. The deployment then uses svn externals to
include the parts of the project it requires:

src/ is externalled into dep/sample_project
configurations/settings_local-.py is file externalled into
dep/sample_project/settings_local.py
configurations/ is file externalled into
dep/scripts/requirements.pip
scripts/{bootstrap,project} are file externalled into dep/scripts/

You end up with a structure like this:

instance
├── environ
│   ├── bin
│   ├── include
│   └── lib
├── htdocs
├── logs
├── run
├── sample_project
│   ├── __init__.py
│   ├── settings.py
│   ├── settings_local.py
│   └── urls.py
└── scripts
├── bootstrap
├── project
└── requirements.pip


The 'bootstrap' script is a simple script that sets up the virtualenv
and installs/upgrades all packages to the specification specified in
requirements.pip, using pip.
The 'project' script is a rc script for plugging into the OS's rc
infrastructure.

Every single file is tracked by VCS, every change in the project
structure is versioned and controlled for change management processes.
Changes to a production environment can be reliably tested, checked
and repeated.
New instances simply require a new settings_local-.py
created in the configuration repo, new packages can be tried in
development and it is simple and repeatable to deploy to production.

There are a number of other tools that I use to do change management
(Fabric and south mainly), but it would take too long to go into those
as well!

Cheers

Tom

-- 
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Piotr Kilczuk
2010/10/26 Tom Evans 

> I'm curious, why can't I talk you into
> Student.objects.all().order_by('-score')[0] ?
>
> It is clearly a superior query :/
>

This would select only one row; there can possibly be multiple students with
a top note.

Am I right? :)

Regards,
Piotr

-- 
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: SELECT * FROM `student` WHERE mark=(select max(mark) from student)

2010-10-26 Thread Tom Evans
I'm curious, why can't I talk you into
Student.objects.all().order_by('-score')[0] ?

It is clearly a superior query :/

Cheers

Tom

On Tue, Oct 26, 2010 at 6:37 AM, ankit rai  wrote:
> say your model name is Student, and it has a field names as marks
>
> query set will be
>
> Student.objects.all().aggregate(Max('marks')
> this will be give you max marks
>
> st=Student.objects.filter(marks__in=Student.objects.all().aggregate(Max('marks')))
>
> --ankit
>
>
> On Tue, Oct 26, 2010 at 9:28 AM, Phlip  wrote:
>>
>> Does anyone have a QuerySet for that?
>>
>> ( BTW please don't try to talk me out of it; I've been doing SQL since
>> 1989 and am fully aware of all the alternatives there. C-; )
>>
>> --
>> 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.
>

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