Re: Python Database Framework

2010-05-14 Thread Joshua Partogi
Thanks Nabil,

I am also looking for something that is as simple as Django ORM but a
standalone ORM that is not tightly coupled. I also like the
ActiveRecord's syntax of Elixir.

Kind regards,
Joshua

--
http://twitter.com/scrum8

On May 14, 7:51 am, Nabil Servais  wrote:
> Hello
> Le 14 mai 2010 à 16:47, Ozgur Yılmaz a écrit :
>
> > Hi everybody,
>
> > Do anyone knows a Python Database framework, which resembles Django's 
> > approach to database programming?
>
> Yes, Elixir :http://elixir.ematia.de/trac/wiki.
>
> > I need it to use outside of Django, for other Python scripts.
>
> > Best regards,
>
> > E.Ozgur Yilmaz
> > Lead Technical Director
> >www.ozgurfx.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: django version 1.1.1 decimalfield invalidoperation

2010-05-14 Thread mendes.rich...@gmail.com
Ok, thanks a lot for your help
Apparently I misunderstood that part, and indeed I replaced it to 20
and 15 leaving again 5 digits.

It should do the trick i'll change it asap.

Thanks again.

Richard



On May 14, 7:38 pm, Karen Tracey  wrote:
> On Fri, May 14, 2010 at 8:22 AM, mendes.rich...@gmail.com <
>
>
>
>
>
> mendes...@gmail.com> wrote:
> > [snip]
>
> > The problem i'm having is with the following model class with the
> > field value:
>
> > class Measurement(models.Model):
> >        measurement_id = models.AutoField("Measurement
> > ID",primary_key=True)
> >        value = models.DecimalField(max_digits=10,decimal_places=5)
> > [snip other irrelevant fields]
>
> > So when i do the following everything works like it should.
>
> > m =
>
> > Measurement(value=34555,date=date,assay_ontology=ao,parameter=p,measurement 
> > _factor=mf,batch=b)
> > m.save()
>
> > But when i add another digit to the value it gives me the following
> > error
> > m =
>
> > Measurement(value=345556,date=date,assay_ontology=ao,parameter=p,measuremen 
> > t_factor=mf,batch=b)
> > m.save()
>
> Yes. You've specified max_digits=10 and decimal_places=5 for value, so the
> maximum allowed digits to the left of the decimal point is 10-5=5. (That is,
> five of your ten max_digits are always dedicated to decimal_places digits to
> the right of the decimal point, so you can only have up to five on the
> left.) Here you are trying to store a number that has six digits to the left
> of the decimal point, which won't fit in the DecimalField you have
> specified.
>
> Traceback (most recent call last):
>
> [traceback snipped]
>
> >  File "/usr/lib/python2.4/decimal.py", line 2267, in _raise_error
> >    raise error, explanation
> > InvalidOperation: Rescale > prec
>
> (Side note more recent Pythons give a somewhat better "explanation":
>
> InvalidOperation: quantize result has too many digits for current context
>
> though that still may not be entirely clear)
>
>
>
> > I tried to find out what was going wrong and deleted the complete
> > table from the database and did a sycdb with a larger max_digits and
> > decimal_places value but that wouldn't help.
>
> If you want more digits to the left of the decimal point, you need to change
> the values of max_digits and decimal_places so that
> max_digits-decimal_places is greater than or equal to the number of digits
> to you want to allow to the left of the decimal point. Since you have not
> said what the new values are that you used, it isn't clear that you
> redefined things in a way to allow six digits to the left of the decimal
> point.
>
> > i did some further checking on the database, and it seems that there
> > is a database problem. When i insert the same values as described
> > above i also get an error stating the following:
>
> > insert into ratstream_measurement
> > values('1143','345556','2008/12/12','1','1','1','5');
> > ERROR:  numeric field overflow
> > DETAIL:  A field with precision 20, scale 15 must round to an absolute
> > value less than 10^5.
>
> From this error message I'd guess you changed max_digits to 20 and
> decimal_places to 15. This still only allows for 20-15=5 digits to the left
> of the decimal point.
>
> > It seems something went wrong with the syncdb but i can't figure out
> > what, does anyone know what i'm doing wrong and can assist me helping
> > to fix the problem.
>
> If you just want more whole digits, make max_digits higher without changing
> decimal_places. You seem to have adjusted both of these values higher in a
> way that did not allow for any more whole digits.
>
> Karen
> --http://tracey.org/kmt/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Python Database Framework

2010-05-14 Thread Ozgur Yılmaz
Now I'm stuck...

As you guys pointed to me, I've searched the web for DJANGO_SETTINGS_MODULE
and found that I can use django.conf.settings to set the settings and that
allowed me to use django in standalone scripts.

To be more clear I use:

from django.conf import settings

then in the code somewhrere else:

settings.configure( DATABASE_ENGINE='sqlite3',
DATABASE_NAME=theFullPathOfTheDatabaseFile )


My whole point of using Django was to be able to use its ORM for project
management purposes. I'm trying to write an open source asset/project
manager for animation studios. So, in my design, I'm going to connect one
projects database  (an sqlite3 database file) then in the same session
(without restarting the whole python shell again) I need to connect to
another projects database.

So when I use settings.configure for the second time I get ( I presume the
very famous ):

RuntimeError: Settings already configured.

errors...

So how should I access another database in one session? should I use the
development version of Django which allows multiple databases?

E.Ozgur Yilmaz
Lead Technical Director
www.ozgurfx.com


On Fri, May 14, 2010 at 6:39 PM, Masklinn  wrote:

> On 2010-05-14, at 17:21 , Tom Evans wrote:
> >
> > Alternatively, all django needs to run is the import location of the
> > settings module [2]. Set it in DJANGO_SETTINGS_MODULE, and then you
> > can just write standard python scripts, importing django bits as
> > needed.
> There are also hacks which let you create a "fake" settings module
> programmatically, but that's what they are: hacks.
>
> Unless `django.conf.settings.configure` has been fixed to work
> correctly instead of being completely broken (aka requiring that
> there is a `DJANGO_SETTINGS_MODULE` and that it points to
> an existing `settings` module when the whole point of the
> function is supposedly to *not* need `DJANGO_SETTINGS_MODULE` in
> the first place)
>
> --
> 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: object is not iterable.

2010-05-14 Thread Gonzalo Delgado
El 14/05/10 18:00, Niels escribió:
> In my template this error  occurs:
>
> Caught an exception while rendering: 'Gallery' object is not iterable
>
> It occurs in this part:
> {% for image in car.images %}
>
>
> Where my models looks like:
>
> from photologue.models import Gallery,Photo
> ...
> class CarDetail(models.Model):
> images = models.ForeignKey(Gallery, null=True, blank=True)
>   

Ah, nevermind my previous response. A foreign key won't be iterable. I
will give you only one object (a Gallery instance in this case).
You may want to use ManyToMany instead of ForeignKey.

-- 
Gonzalo Delgado 

-- 
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: object is not iterable.

2010-05-14 Thread Gonzalo Delgado
El 14/05/10 18:00, Niels escribió:
> In my template this error  occurs:
>
> Caught an exception while rendering: 'Gallery' object is not iterable
>
> It occurs in this part:
> {% for image in car.images %}
>
>
> Where my models looks like:
>
> from photologue.models import Gallery,Photo
> ...
> class CarDetail(models.Model):
> images = models.ForeignKey(Gallery, null=True, blank=True)
>   

When car.images is null (which is allowed by your model definition) it
is not iterable.
Try something like:


{% if car.images %}
  {% for image in car.images %}



-- 
Gonzalo Delgado 

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



object is not iterable.

2010-05-14 Thread Niels
In my template this error  occurs:

Caught an exception while rendering: 'Gallery' object is not iterable

It occurs in this part:
{% for image in car.images %}


Where my models looks like:

from photologue.models import Gallery,Photo
...
class CarDetail(models.Model):
images = models.ForeignKey(Gallery, null=True, blank=True)



Some suggestion?

-- 
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: Using extra() to add table alias

2010-05-14 Thread Austin Gabel
I just found out that I could use join() for this instead.
.query.join((None, 'category', None, None))

This got me what I wanted.



On Fri, May 14, 2010 at 8:06 AM, Austin Gabel  wrote:

> Well, yeah that would work but I would really hate to use a view to work
> around this.
>
>
>
> On Fri, May 14, 2010 at 3:25 AM, michael luger  > wrote:
>
>>
>> this might be a django bug .
>>
>> a workaround using a view for the second usage worked for me . in your
>> case something like:
>>
>> create view category_parent as select * from category;
>>
>> category_list =
>> Category.objects.all().extra(tables=['category_parent'],
>> where=['category.lft BETWEEN category_parent.lft AND
>> category_parent.rgt'])
>>
>> On 13 Mai, 22:23, Austin Gabel  wrote:
>> > I am trying to use the ORM to build the following query:
>> > """SELECT * FROM category AS node, category AS parent WHERE node.lft
>> BETWEEN
>> > parent.lft AND parent.rgt"""
>> >
>> > I am attempting to create the table aliases using .extra() but I'm
>> having a
>> > bit of difficulty.  I have left out the where statements in order to
>> reduce
>> > complexity while troubleshooting this issue.  My current code looks like
>> > this.
>> > category_list = Category.objects.all().extra(tables=['category'])
>> >
>> > The way I understand the documentation [1] is if a table is listed in
>> the
>> > tables argument that already exists in the query, it will add the table
>> with
>> > a generic alias. However, it is simply ignoring the additional table.
>>  This
>> > is the SQL that is produces.
>> >
>> > ('SELECT "category"."id", "category"."lft", "category"."rgt",
>> > "category"."tree_id", "category"."depth", "category"."name" FROM
>> "category"
>> > ORDER BY "category"."name" ASC', ())
>> >
>> > Is this not the correct way to go about adding a table alias?  Am I just
>> > missing something or am I way off track here?
>> >
>> > [1]
>> http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-sele...
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> > For more options, visit this group athttp://
>> groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>

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



Re: SCORM(Sharable Content Object Reference Model) Compliant for Django?

2010-05-14 Thread rleathers
My company has built PowerU, an LCMS with SCORM player, video on
demand, automatic notifications, a deep authorization system,
classroom management, instructor management, and many more features.
We use Adobe Flex with PyAMF and Django with a PostgreSQL back end.
It is essentially a giant django app but it replaces much of what
django includes. For example, we have our own user model.

I'm not at liberty to give away what we have built. It is our hope to
someday share a community version of our product and invite
independent developers to participate in the evolution of PowerU.  For
now, we sell content development services and hosting services. PowerU
is something we offer to customers who are looking for a customizable
LMS experience superior to Moodle, but without the cost of typical
commercial LMS solutions.

Best,
Ryan Leathers
IT Director
American Research Institute


On May 5, 4:30 am, Zeal  wrote:
> Thanks Skylar. django-scorm-rest-rte has really less documentation for
> studying.  Maybe,SCORMis not the hot technology for LMS. Does anyone
> use any else LMS technology with Django in the world? I think LMS is
> really a hot topic in the future, and even now. If there is any
> possibility to ship LMS function in django, Django could be very
> strong and resplendence in the future.
>
> BTW, I've successfully deployed PyAmf modules in my Django's project,
> this allows me to deploy some Flex(adobe) project   which will catch
> the data from Django and return more user-friendly interface to the
> end-user. (Django is really an amazing framework)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Testing custom management commands

2010-05-14 Thread ses1984
If I could add, in my tests, I was testing to see whether the command
executed successfully and I was inspecting the state of the database
after the command executed.

On May 14, 3:04 pm, ses1984  wrote:
> I am interested in writing unit tests to cover some custom commands I
> have written, but I'm unsure how I can pass options to these commands
> through my unittest.TestCase classes.
>
> I have a command to import data from my client's flat file system into
> Django models, which originally existed as a NoArgsCommand with no
> options. I tested it like this:
>
> class ImportDataTest(unittest.TestCase):
>
>     def setUp(self):
>         test_command = import_flatfile_data.Command()
>         test_command.handle_noargs()
>
> I have added a boolean flag option to this command, so I would like to
> split this test case in two, where one case sets up the command as
> with the flag set to true, and one case where the flag is false.
>
> I tried looking for testing coverage of django's own management
> commands, but I was unable to find those.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Testing custom management commands

2010-05-14 Thread ses1984
I am interested in writing unit tests to cover some custom commands I
have written, but I'm unsure how I can pass options to these commands
through my unittest.TestCase classes.

I have a command to import data from my client's flat file system into
Django models, which originally existed as a NoArgsCommand with no
options. I tested it like this:

class ImportDataTest(unittest.TestCase):

def setUp(self):
test_command = import_flatfile_data.Command()
test_command.handle_noargs()

I have added a boolean flag option to this command, so I would like to
split this test case in two, where one case sets up the command as
with the flag set to true, and one case where the flag is false.

I tried looking for testing coverage of django's own management
commands, but I was unable to find those.

-- 
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 CSV module encoding issue

2010-05-14 Thread Karen Tracey
On Fri, May 14, 2010 at 2:34 PM, zweb  wrote:

> I am using DJango CSV module and doing writerrow() on some text data
> generated through tinyce text editor.
>
> I am getting  following error
>
> ascii' codec can't encode character u'\\u2019' in position 337:
> ordinal not in range(128)
>
>  for some reason it cannot handle the single quote in text. How do I
> fix it.
>
> My code:
>
> import csv
> writer = csv.writer(response)
> writer.writerow(["Description:  " + description])
>

Note you appear to be using Python's csv module, nothing provided by Django.
The doc is here: http://docs.python.org/library/csv.html, and if you search
for unicode on that page there is considerable discussion of how to
read/write unicode data using csv. If that does not make it clear, a Python
list would be more appropriate for follow-up, since csv is provided by
Python, not Django.

Karen
-- 
http://tracey.org/kmt/

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

2010-05-14 Thread Bill Freeman
Two choices:

1. Use apostrophe instead of a left or right signle quote when filling
out the form. ;^)

2. Encode the description as utf-8 before writing it.  description is
almost certainly
a unicode string.  It gets coerced to be a bytes string when passed to
python's (not
django's) csv writer.  The default codec in your (and most)
installation(s) is 'ascii'.
So try:

   writer.writerow(["Description: " + description.encode('utf-8')])

However, I'm not sure why you're using csv for stuff with one item per
row.  I guess that it buys you excel quoting.  Wouldn't you rather than
"Desctiption" be a column heading?

On Fri, May 14, 2010 at 2:34 PM, zweb  wrote:
> I am using DJango CSV module and doing writerrow() on some text data
> generated through tinyce text editor.
>
> I am getting  following error
>
> ascii' codec can't encode character u'\\u2019' in position 337:
> ordinal not in range(128)
>
>  for some reason it cannot handle the single quote in text. How do I
> fix it.
>
> My code:
>
> import csv
> writer = csv.writer(response)
> writer.writerow(["Description:  " + description])
>
> --
> 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.



Django CSV module encoding issue

2010-05-14 Thread zweb
I am using DJango CSV module and doing writerrow() on some text data
generated through tinyce text editor.

I am getting  following error

ascii' codec can't encode character u'\\u2019' in position 337:
ordinal not in range(128)

 for some reason it cannot handle the single quote in text. How do I
fix it.

My code:

import csv
writer = csv.writer(response)
writer.writerow(["Description:  " + description])

-- 
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: m2m_changed doesnt work

2010-05-14 Thread imgrey
Thanks a lot!

-- 
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 version 1.1.1 decimalfield invalidoperation

2010-05-14 Thread Karen Tracey
On Fri, May 14, 2010 at 8:22 AM, mendes.rich...@gmail.com <
mendes...@gmail.com> wrote:

> [snip]
>
> The problem i'm having is with the following model class with the
> field value:
>
> class Measurement(models.Model):
>measurement_id = models.AutoField("Measurement
> ID",primary_key=True)
>value = models.DecimalField(max_digits=10,decimal_places=5)
> [snip other irrelevant fields]
>
> So when i do the following everything works like it should.
>
> m =
>
> Measurement(value=34555,date=date,assay_ontology=ao,parameter=p,measurement_factor=mf,batch=b)
> m.save()
>
> But when i add another digit to the value it gives me the following
> error
> m =
>
> Measurement(value=345556,date=date,assay_ontology=ao,parameter=p,measurement_factor=mf,batch=b)
> m.save()
>
>
Yes. You've specified max_digits=10 and decimal_places=5 for value, so the
maximum allowed digits to the left of the decimal point is 10-5=5. (That is,
five of your ten max_digits are always dedicated to decimal_places digits to
the right of the decimal point, so you can only have up to five on the
left.) Here you are trying to store a number that has six digits to the left
of the decimal point, which won't fit in the DecimalField you have
specified.


Traceback (most recent call last):
>
[traceback snipped]

>  File "/usr/lib/python2.4/decimal.py", line 2267, in _raise_error
>raise error, explanation
> InvalidOperation: Rescale > prec
>

(Side note more recent Pythons give a somewhat better "explanation":

InvalidOperation: quantize result has too many digits for current context

though that still may not be entirely clear)


>
> I tried to find out what was going wrong and deleted the complete
> table from the database and did a sycdb with a larger max_digits and
> decimal_places value but that wouldn't help.
>
>
If you want more digits to the left of the decimal point, you need to change
the values of max_digits and decimal_places so that
max_digits-decimal_places is greater than or equal to the number of digits
to you want to allow to the left of the decimal point. Since you have not
said what the new values are that you used, it isn't clear that you
redefined things in a way to allow six digits to the left of the decimal
point.



> i did some further checking on the database, and it seems that there
> is a database problem. When i insert the same values as described
> above i also get an error stating the following:
>
> insert into ratstream_measurement
> values('1143','345556','2008/12/12','1','1','1','5');
> ERROR:  numeric field overflow
> DETAIL:  A field with precision 20, scale 15 must round to an absolute
> value less than 10^5.
>
>
>From this error message I'd guess you changed max_digits to 20 and
decimal_places to 15. This still only allows for 20-15=5 digits to the left
of the decimal point.


> It seems something went wrong with the syncdb but i can't figure out
> what, does anyone know what i'm doing wrong and can assist me helping
> to fix the problem.


If you just want more whole digits, make max_digits higher without changing
decimal_places. You seem to have adjusted both of these values higher in a
way that did not allow for any more whole digits.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 reload an object's member field?

2010-05-14 Thread Steve Bywater
I needed to do something similar just yesterday, and did it the same
way you discovered. I agree, kinda weird:

foo = Foo.objects.get(foo.id)

On May 13, 12:25 pm, Chia Hao Lo  wrote:
> I have a model Foo. If I've got a model instance foo, and I know that
> foo.value may be changed after I got it.
> How can I reload foo.value? For example, this way works:
>
>     foo = Foo.objects.get(foo.id)
>
> Is this the only solution? In case that I'm in a member method of Foo.
> It would looks like this:
>
> def some_method_of_Foo(self, *args):
>     new_self = Foo.objects.get(self.id)
>     self.value = new_self.value
>     ...
>
> I think it's somewhat unclear. How can I do this better?
>
> Thanks.
>
> Ps.
>
> The scenario is like this: I use a model Foo and a field Foo.state to
> record states.
> There is a daemon which do some operations related to Foo and check an
> instance  foo.state regularly.
> The daemon would run or stop based on foo.state. So it needs to reload
> foo.state.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Pluggable Q&A app?

2010-05-14 Thread Nick
I actually just got done writing a QandA app. It's very basic. I don't
have it open yet but I would turn over the source to you if you
wanted.

Here are the features:

Question
Answer
Answerer
Answerer's credentials
site specific QandA (using django.contrib sites)
tagging (using django-tagging)
creation date
update date

It outputs a json api based on several filters

site (required)
general search (optional)
id, id list (optional)
pub_date (optional)
tags (optional)


On May 14, 9:20 am, "bax...@gretschpages.com" 
wrote:
> Can anyone give me any suggestions for a relatively simple, pluggable
> Q&A app? I'm looking for something sorta Stack-Overflow-ish, but I'm
> OK with handling voting, authentication, search, etc. separately.
>
> What I've found so far (OSQA, Askbot, soclone) are far from pluggable.
> I don't want a whole other site, just an app.
>
> 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 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: HttpResponseRedirect(request.path) after request.POST issue

2010-05-14 Thread marty3d
I finally went half and half here, by posting to an /vote//
url. Personally, I think handling the GET in the tag and the POST in a
view is a bit messy, but perhaps I find a better solution later.
After I got that to work properly, I also implemented an ajax version.
I have never done that in Django before, is there some sort of
standard procedure for doing that? I posted to the same view with
an .is_ajax() clause, perhaps it's preferred to have a separate view
handling ajax calls? Either way, it worked after I figured out some
jQuery stuff (I'm a total n00b with that!).

The reasons I'm doing this instead of just grabbing django-voting, is
1. to learn! and 2. I wanted to use cookies instead of IP address (it
would be a shame if only one person in a whole office sharing the same
IP could vote, right?) or have everyone creating a user object just
for that.

Thanks all for chiming in with good advices! This is such a great
community!
/Martin

On May 14, 10:41 am, Tom Evans  wrote:
> On Thu, May 13, 2010 at 6:11 PM, marty3d  wrote:
> > Thanks, that's a shame...
> > So I'm now trying to do the request.POST stuff in a view instead.
> > Since the idea is to have the voting app as decoupled as possible, is
> > there a slick way to pass, perhaps the whole object in this case, but
> > at least the name of the model or similar together with the post?
>
> > Thanks!
> > /Martin
>
> I can think of three options off the top of my head:
>
> 1) Have the voting app always submit to one view, regardless of the
> current view. The voting app form could include a 'next' parameter,
> indicating where to send the user back to.
>
> 2) Write the form processing code as a middleware. If you dont want
> every page to handling posting this voting app form, use the
> decorator_from_middleware adapter to turn your middleware into
> something you can decorate specific views with.
>
> 3) Handle posts from the voting app with AJAX, always posting to the
> same page, and updating the displayed content in the page when done.
>
> 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 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: M2M with Intermediary - Django Admin Support - Doesn't appear?

2010-05-14 Thread Nuno Maltez
Hmmm ... you should have an inline formset at the bottom to add firms
to your Article, with an associated input box forthe rating.

If I understand correctly, each relation Article-Firm now needs a
rating (mandatory), sou you can't just select Firms from a
filter_horizontal widget - you need a way to input the rating as well.

Nuno

-- 
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: m2m_changed doesnt work

2010-05-14 Thread Karen Tracey
On Fri, May 14, 2010 at 8:19 AM, imgrey  wrote:

> Good Day
>
> Im trying to create machanism for tracking changes in model's
> ManyToMany fields. For some reason django connects signals, but wont
> execute callback:
>
> """
> from django.db import models
> from django.db.models import signals
> from django.db.models.base import ModelBase
>
> def add_signals(cls):
>def m2m_changed(sender, instance, action, *args, **kwargs):
>print instance, sender # NEVER BEING EXECUTED. WTF ?
>
>if not kwargs['pk_set']:
>return
>model = kwargs['model']
>
>m2m_fields = dict([(f.name, f) for f in cls._meta.many_to_many if
> f.name not in cls._exclude])
>for field_name in m2m_fields.keys():
>modelfield = m2m_fields[field_name]
>rel = getattr(modelfield, 'rel')
>if rel and rel.through:
>value = rel.through.objects.all()
>
>print field_name, rel, rel.through # THIS WORKS
>signals.m2m_changed.connect(m2m_changed, sender=rel.through)
>

Your signal handler is a local function, so you must pass weak=False on the
connect() in order to avoid it being garbage collected, which will
disconnect the signal. See the note (3rd paragraph) in the Warning here:
http://docs.djangoproject.com/en/dev/ref/signals/#module-django.db.models.signals

Karen
-- 
http://tracey.org/kmt/

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

2010-05-14 Thread Javier Guerra Giraldez
On Fri, May 14, 2010 at 8:37 AM, Nuno Maltez  wrote:
> Sure: 
> http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists
>
> myfilter = { var_field: "found" }
> Foo.objects.filter(**myfilter}

or even:

Foo.objects.filter (**{var_field+'__eq':'found'})


if you want to use a different operator instead of the default '__eq'


-- 
Javier

-- 
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: Python Database Framework

2010-05-14 Thread Masklinn
On 2010-05-14, at 17:21 , Tom Evans wrote:
> 
> Alternatively, all django needs to run is the import location of the
> settings module [2]. Set it in DJANGO_SETTINGS_MODULE, and then you
> can just write standard python scripts, importing django bits as
> needed.
There are also hacks which let you create a "fake" settings module
programmatically, but that's what they are: hacks.

Unless `django.conf.settings.configure` has been fixed to work
correctly instead of being completely broken (aka requiring that
there is a `DJANGO_SETTINGS_MODULE` and that it points to 
an existing `settings` module when the whole point of the
function is supposedly to *not* need `DJANGO_SETTINGS_MODULE` in
the first place)

-- 
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: Python Database Framework

2010-05-14 Thread Shawn Milochik
There's SQLAlchemy, but it's not nearly as simple as the Django ORM. However, 
nobody's stopping you from using the Django ORM (or the templates) in other 
projects that don't use the rest of Django. You will have to make a minimum 
settings.py or make certain values available in the scope of your project, but 
it can be done.

Also, depending on the project, I love using pymongo and MongoDB in Python. The 
syntax is very Pythonic -- pretty much everything is a Python dictionary. But 
MongoDB is a non-relational database, so if you need one of those you should 
probably look at SQLAlchemy or find a good blog post on using the Django ORM in 
arbitrary Python scripts.

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.



Re: Python Database Framework

2010-05-14 Thread Tom Evans
On Fri, May 14, 2010 at 4:12 PM, Ozgur Yılmaz  wrote:
> thanks guys for being that fast...
>
> Elixir seems what I'm looking for...
>
> Russel: I've tried to figure out how to use the Djanog-ORM, but I couldn't
> find any good way other than using Djanog-Standalone
> (http://pypi.python.org/pypi/django-standalone/0.4) and it has some side
> effects. And I like to here if anybody has a good solution about using the
> Django ORM
>
> Regards,
>
> E.Ozgur Yilmaz
> Lead Technical Director
> www.ozgurfx.com
>

Theres nothing particularly complex with using django outside of a web server.

The simplest way is to hook into management commands [1] and use that
as the entry point to your program.

Alternatively, all django needs to run is the import location of the
settings module [2]. Set it in DJANGO_SETTINGS_MODULE, and then you
can just write standard python scripts, importing django bits as
needed.

Googling for DJANGO_SETTINGS_MODULE standalone brings a plethora of
blogs documenting how others have done it.

Cheers

Tom

[1] http://docs.djangoproject.com/en/1.1/howto/custom-management-commands/
[2] 
http://docs.djangoproject.com/en/1.1/topics/settings/#designating-the-settings

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

2010-05-14 Thread thanos
Django is great and I've writing quite a lot with it but my projects
need dynamic multiple database connections. Now with 1.2 I might do
things differently. But I would miss elixir.ext.versioned !

thanos

On May 14, 11:07 am, Jirka Vejrazka  wrote:
> > Do anyone knows a Python Database framework, which resembles Django's
> > approach to database programming? I need it to use outside of Django, for
> > other Python scripts.
>
> Any reason why you wouldn't Django itself? I do use the ORM to
> multiple projects that have no relation to web. Works very well.
>
>    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 
> athttp://groups.google.com/group/django-users?hl=en.

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



Delete cache item when model changes

2010-05-14 Thread Torsten Bronger
Hallöchen!

I'd like to clean up the cache when an updated model instance is
saved to the database backend.

Let's assume that I have a model "Person", and the user can view the
person's information on a webpage.  However, much data must be
collected for this webpage, so it's a costly operation and should be
cached.

No problem, because I can generate a cache key containing the
person's primary key, the timestamp, and the user's settings
(e.g. language) and save the collected data into the cache.

Now some of this collected data changes.  How can I delete all cache
keys that have become invalid by this?  I could store all keys in a
CharField in the Person model and use signals.  Is there a better
approach?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
   Jabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.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: Python Database Framework

2010-05-14 Thread Ozgur Yılmaz
thanks guys for being that fast...

Elixir seems what I'm looking for...

Russel: I've tried to figure out how to use the Djanog-ORM, but I couldn't
find any good way other than using Djanog-Standalone (
http://pypi.python.org/pypi/django-standalone/0.4) and it has some side
effects. And I like to here if anybody has a good solution about using the
Django ORM

Regards,

E.Ozgur Yilmaz
Lead Technical Director
www.ozgurfx.com


On Fri, May 14, 2010 at 5:54 PM, thanos  wrote:

> Elixir gets my vote.
>
> I now always use http://www.sqlalchemy.org/ for any db work. But
> Elixir is cool. I used it with
> http://elixir.ematia.de/apidocs07/elixir.ext.versioned.html
> and it saved my bacon !
>
>
>
> On May 14, 10:51 am, Nabil Servais  wrote:
> > Hello
> > Le 14 mai 2010 à 16:47, Ozgur Yılmaz a écrit :
> >
> > > Hi everybody,
> >
> > > Do anyone knows a Python Database framework, which resembles Django's
> approach to database programming?
> >
> > Yes, Elixir :http://elixir.ematia.de/trac/wiki.
> >
> > > I need it to use outside of Django, for other Python scripts.
> >
> > > Best regards,
> >
> > > E.Ozgur Yilmaz
> > > Lead Technical Director
> > >www.ozgurfx.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 athttp://
> groups.google.com/group/django-users?hl=en.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> > For more options, visit this group athttp://
> groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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: Python Database Framework

2010-05-14 Thread Jirka Vejrazka
> Do anyone knows a Python Database framework, which resembles Django's
> approach to database programming? I need it to use outside of Django, for
> other Python scripts.

Any reason why you wouldn't Django itself? I do use the ORM to
multiple projects that have no relation to web. Works very well.

   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: Python Database Framework

2010-05-14 Thread thanos
Elixir gets my vote.

I now always use http://www.sqlalchemy.org/ for any db work. But
Elixir is cool. I used it with
http://elixir.ematia.de/apidocs07/elixir.ext.versioned.html
and it saved my bacon !



On May 14, 10:51 am, Nabil Servais  wrote:
> Hello
> Le 14 mai 2010 à 16:47, Ozgur Yılmaz a écrit :
>
> > Hi everybody,
>
> > Do anyone knows a Python Database framework, which resembles Django's 
> > approach to database programming?
>
> Yes, Elixir :http://elixir.ematia.de/trac/wiki.
>
> > I need it to use outside of Django, for other Python scripts.
>
> > Best regards,
>
> > E.Ozgur Yilmaz
> > Lead Technical Director
> >www.ozgurfx.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 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Python Database Framework

2010-05-14 Thread Russell Keith-Magee
On Fri, May 14, 2010 at 10:47 PM, Ozgur Yılmaz  wrote:
> Hi everybody,
>
> Do anyone knows a Python Database framework, which resembles Django's
> approach to database programming? I need it to use outside of Django, for
> other Python scripts.

Is there some fundamental reason that you can't just use Django's ORM?
Sure, Django is primarily designed for use building websites, but you
can easily write standalone scripts that use Django's libraries

Yours,
Russ Magee %-)

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



Re: Python Database Framework

2010-05-14 Thread Masklinn
On 2010-05-14, at 16:47 , Ozgur Yılmaz wrote:
> 
> Hi everybody,
> 
> Do anyone knows a Python Database framework, which resembles Django's
> approach to database programming? I need it to use outside of Django, for
> other Python scripts.


Well you could use Django itself, there are a few quirks but that's a
possibility, or you could check out SQLAlchemy and its declarative layer
(or Elixir, another declarative layer on top of SQLA).

SQLAlchemy is bigger in scope and complexity than Django's ORM, but also
a good bit more flexible. Might fit your needs well.

-- 
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: Python Database Framework

2010-05-14 Thread Nabil Servais
Hello
Le 14 mai 2010 à 16:47, Ozgur Yılmaz a écrit :

> Hi everybody,
> 
> Do anyone knows a Python Database framework, which resembles Django's 
> approach to database programming?

Yes, Elixir : http://elixir.ematia.de/trac/wiki. 


> I need it to use outside of Django, for other Python scripts.
> 
> Best regards,
> 
> E.Ozgur Yilmaz
> Lead Technical Director
> www.ozgurfx.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.

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



Python Database Framework

2010-05-14 Thread Ozgur Yılmaz
Hi everybody,

Do anyone knows a Python Database framework, which resembles Django's
approach to database programming? I need it to use outside of Django, for
other Python scripts.

Best regards,

E.Ozgur Yilmaz
Lead Technical Director
www.ozgurfx.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: Update Query

2010-05-14 Thread Bill Freeman
Cool.

So I guess we have a doc bug against the queryset API reference.

Sim, if you're still reading this, and updating stuff in the database is
what you were trying to do, then turn you computes collection of
changes into a dictionary (if it isn't one already), "d" below, and do:

   User.objects.filter(id=11).update(**d)

Bill

On Fri, May 14, 2010 at 10:30 AM, Tom Evans  wrote:
> On Fri, May 14, 2010 at 3:26 PM, Bill Freeman  wrote:
>> Actually, there would be a real advantage to doing update in the
>> DB rather than instantiating the model, changing it, and saving it,
>> since sql update is a single transaction.  If that's what queryset
>> update does, then the only issue with your version is that you
>> needed two asterisks, passing "some_dictionary" as keyword
>> arguments.  (We know from the error message that update
>> doesn't take any positional arguments beyond self, but it
>> could take keyword arguments.)
>>
>> The trouble is that I don't see update as a documented queryset
>> method at:
>>   
>> http://docs.djangoproject.com/en/1.1/ref/models/querysets/#ref-models-querysets
>>
>> So I'd have to look at the code to see what it does.  Also, if it's
>> undocumented, it should probably be considered internal and
>> subject to change.  If you're seeing it documented somewhere,
>> I'd appreciate a url.
>
> http://docs.djangoproject.com/en/1.1/topics/db/queries/#topics-db-queries-update
>
> 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.
>
>

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

2010-05-14 Thread Tom Evans
On Fri, May 14, 2010 at 3:26 PM, Bill Freeman  wrote:
> Actually, there would be a real advantage to doing update in the
> DB rather than instantiating the model, changing it, and saving it,
> since sql update is a single transaction.  If that's what queryset
> update does, then the only issue with your version is that you
> needed two asterisks, passing "some_dictionary" as keyword
> arguments.  (We know from the error message that update
> doesn't take any positional arguments beyond self, but it
> could take keyword arguments.)
>
> The trouble is that I don't see update as a documented queryset
> method at:
>   
> http://docs.djangoproject.com/en/1.1/ref/models/querysets/#ref-models-querysets
>
> So I'd have to look at the code to see what it does.  Also, if it's
> undocumented, it should probably be considered internal and
> subject to change.  If you're seeing it documented somewhere,
> I'd appreciate a url.

http://docs.djangoproject.com/en/1.1/topics/db/queries/#topics-db-queries-update

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

2010-05-14 Thread Peter Herndon

On May 14, 2010, at 5:43 AM, Tom Evans wrote:

> On Thu, May 13, 2010 at 7:31 PM, Daniel Roseman  wrote:
>> 
>> 
>> On May 13, 5:35 pm, Peter Herndon  wrote:
>>> On May 13, 2010, at 10:29 AM, TallFurryMan wrote:
>>> 
 Hello Django users,
>>> 
 Is there a particular reason why using a related OneToOneField raises
 DoesNotExist instead of returning None?
>>> 
>>> Any query you make that is supposed to return one or more instances, that 
>>> instead cannot find any results, returns a DoesNotExist.
>> 
>> Not true - a .filter() query returns an empty QuerySet if no results
>> are found. However a .get() query does raise DoesNotExist if it
>> doesn't find anything - which is the exact equivalent of a
>> OneToOneField lookup.
> 
> To get super pedantic, he said 'any query that is supposed to return
> one or more instances' would raise a DoesNotExist. You countered with
> a .filter() query, which returns 0 or more instances.
> 
> Cheers
> 
> Tom

:)  Indeed, I knew what I *meant* to say, but I must admit I didn't bother to 
look up the details before I wrote it all down.  Further, I often forget that 
get_or_create returns the obj, boolean tuple, leading to the exact bug Daniel 
pointed out. I do that in my own code whenever I first use get_or_create again 
after an absence, and have to debug it.  Mea culpa, I replied carelessly, 
points to Daniel for correcting me.

But in *spirit* I was correct!  :D  Sadly, though, this is neither horseshoes 
nor hand-grenades, so close doesn't really count for much.

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

2010-05-14 Thread Bill Freeman
Actually, there would be a real advantage to doing update in the
DB rather than instantiating the model, changing it, and saving it,
since sql update is a single transaction.  If that's what queryset
update does, then the only issue with your version is that you
needed two asterisks, passing "some_dictionary" as keyword
arguments.  (We know from the error message that update
doesn't take any positional arguments beyond self, but it
could take keyword arguments.)

The trouble is that I don't see update as a documented queryset
method at:
   
http://docs.djangoproject.com/en/1.1/ref/models/querysets/#ref-models-querysets

So I'd have to look at the code to see what it does.  Also, if it's
undocumented, it should probably be considered internal and
subject to change.  If you're seeing it documented somewhere,
I'd appreciate a url.  I guess that I could go look at the code, but
I've got a sneaking suspicion that that it's a worker method used
in the implementation of filter, exclude, etc.

So, the only way that I know to run a SQL UPDATE is with custom
SQL.  (I'm pretty sure that you can't do it with extra().)

Bill

On Fri, May 14, 2010 at 8:33 AM, zinckiwi  wrote:
> On May 13, 6:48 pm, Bill Freeman  wrote:
>> Or you could be right.  I'm still not clear on the OP's intent.
>
> I suspect both would work, with my solution relying on a queryset
> containing a single object. Yours is cleaner!
>
> Regards
> Scott
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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: Tree view me

2010-05-14 Thread Peter Herndon

On May 14, 2010, at 4:16 AM, cyrux cyrux wrote:

> I have a simple task to accomplish. I have some hierarchal data in my
> database which needs to be displayed in a UI. It needs to be simple
> and preferably in a expandable tree format (although a non -expandable
> should work as well). This is what I am looking for
> http://source.mihelac.org/x/treetable/tests/example2.html#
> 
> I have been looking django since last week and I haven't gone
> anywhere. I have looked at a couple of extensions , but I am not sure
> if they would work. So , is it possible to achieve some thing like the
> above link in django ? I have looked into django-mptt and django-
> treemneu but seems consuing. I have never really worked on front end
> languages like HTML , PHP , so the template part of django confuses
> me. There is so much of stuff happening behind the scenese that
> confuses me. If somebody can tell me if this is possible, i can spend
> may be a day or more looking into it, else I will probably go for php
> stuff

Django is front-end agnostic.  There may be individual reusable apps that 
provide what you need, but Django itself does not come with a tree view, nor 
does it pick a particular JavaScript library to integrate.  This means you have 
all the flexibility you may need to build whatever components your application 
requires.  This also means you often have the burden of developing the 
front-end by yourself.

In my case, I have had good results incorporating the jQuery Dynatree plugin 
into my application.  However, I did the integration entirely myself.

If you only have "a day or more" to invest on building the front-end, and you 
are not comfortable building HTML and wiring up JavaScript, but you *are* 
comfortable with PHP, then PHP may be the better choice for your needs.  On the 
other hand, if you continue to build web applications, you will need to develop 
a certain expertise with HTML, CSS and JavaScript, in addition to your 
server-side framework and its language, so you may want to put the time in to 
learn the tools now.

Hope that helps,

---Peter Herndon

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



Pluggable Q&A app?

2010-05-14 Thread bax...@gretschpages.com
Can anyone give me any suggestions for a relatively simple, pluggable
Q&A app? I'm looking for something sorta Stack-Overflow-ish, but I'm
OK with handling voting, authentication, search, etc. separately.

What I've found so far (OSQA, Askbot, soclone) are far from pluggable.
I don't want a whole other site, just an app.

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: Is it ok to super/save() twice in model.save()?

2010-05-14 Thread Richard Colley
Thanks Scott, that's more or less what we've finalised on.  Appreciate
your feedback!

Richard

On May 14, 10:28 pm, zinckiwi  wrote:
> Righto -- unfortunately that's the best solution I've come up with to
> date. Here's the detailed version:
>
> # models.py
> def get_upload_path(instance, filename):
>     return "%s/%s/%s" % (instance.__class__.__name__.lower(),
> instance.uuid, filename,)
>
> def get_uuid():
>     import uuid
>     return str(uuid.uuid4())
>
> class MyModel(models.Model):
>     ...
>     pdf = models.FileField(max_length=200, upload_to=get_upload_path)
>     uuid = models.CharField(max_length=36, default=get_uuid,
> editable=False)
>
> That results in //.
>
> I certainly did entertain a minimal-save-to-get-the-PK followed by the
> "real" save, but didn't even get as far as discovering that it could
> cause problems with shortcut functions. What turned me off at the
> outset was needing to provide fake or default values for every other
> field in the model, deleting that one if the "real" save failed, etc.
> Seemed like a lot of busywork and prone to error.
>
> Regards
> Scott
>
> On May 13, 10:52 pm, Richard Colley  wrote:
>
> > Exactly as you had described ... I wanted to upload images to paths
> > with the model instance's id in it.  Seemed easier for a human to
> > relate to that way (in case of maintenance outside of django).
> > However, the uuid approach or similar may be the way forward.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Using a variable for a field name in a filter?

2010-05-14 Thread Nuno Maltez
Sure: http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists

myfilter = { var_field: "found" }
Foo.objects.filter(**myfilter}

hth,
Nuno

On Fri, May 14, 2010 at 2:19 PM, derek  wrote:
> Given a model Foo, with a field bar:
> Foo.objects.filter(bar = "found")
> works just fine.
>
> But, in my case, different fields are needed at different times, so I
> would like to use:
> Foo.objects.filter(var_field = "found")
> where "var_field" is a variable which will be set to the name of a
> field (such as "bar").
>
> The above is incorrect - how do I accomplish this?
>
> Thanks
> Derek
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Using a variable for a field name in a filter?

2010-05-14 Thread derek
Given a model Foo, with a field bar:
Foo.objects.filter(bar = "found")
works just fine.

But, in my case, different fields are needed at different times, so I
would like to use:
Foo.objects.filter(var_field = "found")
where "var_field" is a variable which will be set to the name of a
field (such as "bar").

The above is incorrect - how do I accomplish this?

Thanks
Derek

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



Re: Using extra() to add table alias

2010-05-14 Thread Austin Gabel
Well, yeah that would work but I would really hate to use a view to work
around this.


On Fri, May 14, 2010 at 3:25 AM, michael luger
wrote:

>
> this might be a django bug .
>
> a workaround using a view for the second usage worked for me . in your
> case something like:
>
> create view category_parent as select * from category;
>
> category_list =
> Category.objects.all().extra(tables=['category_parent'],
> where=['category.lft BETWEEN category_parent.lft AND
> category_parent.rgt'])
>
> On 13 Mai, 22:23, Austin Gabel  wrote:
> > I am trying to use the ORM to build the following query:
> > """SELECT * FROM category AS node, category AS parent WHERE node.lft
> BETWEEN
> > parent.lft AND parent.rgt"""
> >
> > I am attempting to create the table aliases using .extra() but I'm having
> a
> > bit of difficulty.  I have left out the where statements in order to
> reduce
> > complexity while troubleshooting this issue.  My current code looks like
> > this.
> > category_list = Category.objects.all().extra(tables=['category'])
> >
> > The way I understand the documentation [1] is if a table is listed in the
> > tables argument that already exists in the query, it will add the table
> with
> > a generic alias. However, it is simply ignoring the additional table.
>  This
> > is the SQL that is produces.
> >
> > ('SELECT "category"."id", "category"."lft", "category"."rgt",
> > "category"."tree_id", "category"."depth", "category"."name" FROM
> "category"
> > ORDER BY "category"."name" ASC', ())
> >
> > Is this not the correct way to go about adding a table alias?  Am I just
> > missing something or am I way off track here?
> >
> > [1]
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-sele...
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> > For more options, visit this group athttp://
> groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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: Upload code from development server to local server

2010-05-14 Thread Archidjango
Alright, thanks for your input! I must admit I didn't read it yet
(**embarrassed look to the ground**). I'll do that and if I still have
problems, I'll come back to you ;-)

Cheers,

On May 14, 1:40 pm, Alessandro Pasotti  wrote:
> 2010/5/14 Archidjango 
>
>
>
>
>
> > Hey all,
>
> > I'm a little confused, but I guess that's normal being a real
> > newbie :-) .
>
> > I tried to upload code written on my development server to a "real"
> > web server.
>
> > I uploaded the code through ftp and made the url-forward, tested an
> > dummy "index.html" so there's no problem on that side. The connection
> > seems to be fine.
>
> > However, the server (?) does not seem to recognize the python code.
> > The first line I get on a browser when navigating to the website's url
> > is the following:
>
> > {% extends "xyz.html" %} {% load i18n %} {% block title %}{% trans
> > "Calculate" %}{% endblock %} {% block media %} {% endblock %} {% block
> > content %}
>
> > On my development server the whole thing works fine, but I don't
> > exactly know what to do to make the online version work as well.
>
> > Does anyone have an idea on how to solve this problem?
>
> Hi,
>
> you don't give much details about your intended server setup...
> just to be sure, did you read the django manual page on deployment ?
>
> Here is the link, as you will see, you have many different possibilities,
> mod_wsgi being the recommended one:
>
> docs.djangoproject.com/en/1.1/howto/deployment/#howto-deployment-index
>
> --
> Alessandro Pasotti
> w3:  www.itopen.it
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

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



Re: Django Project & App Structure

2010-05-14 Thread zinckiwi
> Voila, I now have created an app that is independent of it's
> surrounding project.  The only thing left is the fact that my app has
> templates, which I understand is a no-no when making reusable apps.
> I'll start working on that later, as I'm satisfied now with no strict
> backwards dependencies.

It's not an absolute no-no. View templates are pretty pointless,
because markup, page structure, CSS hooks, template {% block %}s etc.
differ so widely. However, small inclusion tags, if "atomic" enough,
may benefit from some default templates. If you want a default
template in your reusable app, structure it thusly:

myapp
/templates
/myapp
my_tag.html
/templatetags
myapp_tags.py

And refer to it simply as "myapp/my_tag.html". That way, the consumer
of your app can override it by having a "myapp/my_tag.html" of their
own in their project's templates directory.

Regards
Scott

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



Re: Django Project & App Structure

2010-05-14 Thread ryan west
Hey Scott, thanks for the reply!

I just figured that out the hard way actually, but I appreciate your
response.

My new directory structure now looks like:

/home/website/djangoprojects/mydjangoproject/
--- /
manage.py
--- /
settings.py
--- /
urls.py

/home/website/djangoapps/mydjangoapp/
-- /models.py
-- /admin.py
-- /urls.py
-- /view.py

My webserver (dreamhost) runs passenger, so I had to update my
passenger_wsgi.py file to include path of my projects (/home/website/
djangoprojects) as well as my apps (/home/website/djangoapps).

The tricky (at first) part came when I needed to fill the DB of my
project w/ tables required by my app(s).  To do this, I had to add the
same paths above to my manage.py file, so that when it was executed
the paths would be in there for the script to find and import the
model information.

Voila, I now have created an app that is independent of it's
surrounding project.  The only thing left is the fact that my app has
templates, which I understand is a no-no when making reusable apps.
I'll start working on that later, as I'm satisfied now with no strict
backwards dependencies.

Thanks again Scott.

I will be writing a blogpost about this shortly on how to create a
reusable django app on a shared webserver such as Dreamhost - in an
attempt to gather disparate information into one, easy to follow and
up to date post.  I will post back with the perma when it's done.

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

2010-05-14 Thread zinckiwi
On May 13, 6:48 pm, Bill Freeman  wrote:
> Or you could be right.  I'm still not clear on the OP's intent.

I suspect both would work, with my solution relying on a queryset
containing a single object. Yours is cleaner!

Regards
Scott

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



Re: Django Project & App Structure

2010-05-14 Thread zinckiwi
> When I try to run syncdb, manage.py returns an error saying that my
> app (djangoapp) could not be found.  I've tried to add the URL of the
> app to the system path so that it would be accessible from external
> directories - to do this I've tried adding the absolute URL of my app
> to my project's settings.py file, but either it doesn't work, or I'm
> doing it wrong:
>
> sys.path.append('/home/website/djangoapp')

If you're asking python to look for 'djangoapp', then it won't find it
in '/home/website/djangoapp'. (It would effectively be looking for '/
home/website/djangoapp/djangoapp' -- and failing.)

Doing sys.path.append('/home/website') should work.

Regards
Scott

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



Re: Is it ok to super/save() twice in model.save()?

2010-05-14 Thread zinckiwi
Righto -- unfortunately that's the best solution I've come up with to
date. Here's the detailed version:

# models.py
def get_upload_path(instance, filename):
return "%s/%s/%s" % (instance.__class__.__name__.lower(),
instance.uuid, filename,)

def get_uuid():
import uuid
return str(uuid.uuid4())

class MyModel(models.Model):
...
pdf = models.FileField(max_length=200, upload_to=get_upload_path)
uuid = models.CharField(max_length=36, default=get_uuid,
editable=False)

That results in //.

I certainly did entertain a minimal-save-to-get-the-PK followed by the
"real" save, but didn't even get as far as discovering that it could
cause problems with shortcut functions. What turned me off at the
outset was needing to provide fake or default values for every other
field in the model, deleting that one if the "real" save failed, etc.
Seemed like a lot of busywork and prone to error.

Regards
Scott


On May 13, 10:52 pm, Richard Colley  wrote:
> Exactly as you had described ... I wanted to upload images to paths
> with the model instance's id in it.  Seemed easier for a human to
> relate to that way (in case of maintenance outside of django).
> However, the uuid approach or similar may be the way forward.

-- 
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 version 1.1.1 decimalfield invalidoperation

2010-05-14 Thread mendes.rich...@gmail.com
Hello Karen,

Thanks for your reply, i checked the code from the ticket and it was
indeed already changed in the current version.
The specs of the system i',m using are;

Python 2.4.3
Django 1.1.1 final
Database Postgresql
Interface postgresql_psycopg2

The problem i'm having is with the following model class with the
field value:

class Measurement(models.Model):
measurement_id = models.AutoField("Measurement
ID",primary_key=True)
value = models.DecimalField(max_digits=10,decimal_places=5)
date = models.DateField()
assay_ontology = models.ForeignKey(Assay_Ontology)
parameter = models.ForeignKey(Parameter)
measurement_factor = models.ForeignKey(Measurement_Factor)
batch = models.ForeignKey(Batch)

So when i do the following everything works like it should.

m =
Measurement(value=34555,date=date,assay_ontology=ao,parameter=p,measurement_factor=mf,batch=b)
m.save()

But when i add another digit to the value it gives me the following
error
m =
Measurement(value=345556,date=date,assay_ontology=ao,parameter=p,measurement_factor=mf,batch=b)
m.save()

Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/django/db/models/base.py",
line 410, in save
self.save_base(force_insert=force_insert,
force_update=force_update)
  File "/usr/lib/python2.4/site-packages/django/db/models/base.py",
line 483, in save_base
values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname)
or f.pre_save(self, True))) for f in meta.local_fields if not
isinstance(f, AutoField)]
  File "/usr/lib/python2.4/site-packages/django/db/models/fields/
__init__.py", line 625, in get_db_prep_save
self.max_digits, self.decimal_places)
  File "/usr/lib/python2.4/site-packages/django/db/backends/
__init__.py", line 404, in value_to_db_decimal
return util.format_number(value, max_digits, decimal_places)
  File "/usr/lib/python2.4/site-packages/django/db/backends/util.py",
line 130, in format_number
return u'%s' % str(value.quantize(decimal.Decimal(".1") **
decimal_places, context=context))
  File "/usr/lib/python2.4/decimal.py", line 1824, in quantize
return self._rescale(exp._exp, rounding, context, watchexp)
  File "/usr/lib/python2.4/decimal.py", line 1870, in _rescale
return context._raise_error(InvalidOperation, 'Rescale > prec')
  File "/usr/lib/python2.4/decimal.py", line 2267, in _raise_error
raise error, explanation
InvalidOperation: Rescale > prec

I tried to find out what was going wrong and deleted the complete
table from the database and did a sycdb with a larger max_digits and
decimal_places value but that wouldn't help.

i did some further checking on the database, and it seems that there
is a database problem. When i insert the same values as described
above i also get an error stating the following:

insert into ratstream_measurement
values('1143','345556','2008/12/12','1','1','1','5');
ERROR:  numeric field overflow
DETAIL:  A field with precision 20, scale 15 must round to an absolute
value less than 10^5.

It seems something went wrong with the syncdb but i can't figure out
what, does anyone know what i'm doing wrong and can assist me helping
to fix the problem.

thanks in advance,

Richard



On May 11, 4:51 pm, Karen Tracey  wrote:
> On Tue, May 11, 2010 at 9:49 AM, mendes.rich...@gmail.com <
>
>
>
>
>
> mendes...@gmail.com> wrote:
> > On our production server we are running the last official release
> > 1.1.1,
> > When i started uploading big decimal values i ran into trouble and
> > came across a ticket which described the error.
>
> > This was ticket 10692 and it was solved.
>
> > Unfortunately i couldn't track down which files should be replaced by
> > the altered code from the ticket.
> > Could anyone help me out and explain me how this normally works
> > outside the svn repository, so which files should i replace and where
> > can i find the altered code for those parts.
>
> > your help would be greatly appreciated,
>
> Ticket #10692:http://code.djangoproject.com/ticket/10692
>
> includes comments linking to the changesets where it was fixed, for example
> on trunk:
>
> http://code.djangoproject.com/changeset/10545
>
> shows the files and exact changes that were made.
>
> Note however, this ticket was fixed in trunk and the 1.0.X branch, which
> implies that the fix already exists in the 1.1 (and all subsequent)
> releases. The changes include a test of the problem that was fixed, and that
> tests passes in 1.1.1 and current trunk. Thus you should not be seeing this
> problem if you are running 1.1.1.
>
> Perhaps if you described exactly what problem you are seeing, including the
> version of Python you are running, someone could help in figuring out what
> is going on.
>
> Karen
> --http://tracey.org/kmt/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsu

m2m_changed doesnt work

2010-05-14 Thread imgrey
Good Day

Im trying to create machanism for tracking changes in model's
ManyToMany fields. For some reason django connects signals, but wont
execute callback:

"""
from django.db import models
from django.db.models import signals
from django.db.models.base import ModelBase

def add_signals(cls):
def m2m_changed(sender, instance, action, *args, **kwargs):
print instance, sender # NEVER BEING EXECUTED. WTF ?

if not kwargs['pk_set']:
return
model = kwargs['model']

m2m_fields = dict([(f.name, f) for f in cls._meta.many_to_many if
f.name not in cls._exclude])
for field_name in m2m_fields.keys():
modelfield = m2m_fields[field_name]
rel = getattr(modelfield, 'rel')
if rel and rel.through:
value = rel.through.objects.all()

print field_name, rel, rel.through # THIS WORKS
signals.m2m_changed.connect(m2m_changed, sender=rel.through)

class ModelWithChangelogBase(ModelBase):
def __new__(cls, name, bases, attrs):
model = ModelBase.__new__(cls, name, bases, attrs)
model._exclude = []
add_signals(model)
return model

class ModelWithChangelog(models.Model):
__metaclass__ = ModelWithChangelogBase
class Meta:
abstract = True
"""

An example of usage:

class MyModelChangelog(models.Model)
exclude = []

class MyModel(ModelWithChangelog):
attachments = models.ManyToManyField(File)

class Changelog:
model = MyModelChangelog

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



Override widget for one specific field in admin change_list page

2010-05-14 Thread Massimiliano della Rovere
I'm trying to override the widget used in the changelist page for one
field of a model.
The field is updated by an external daemon and is defined as:
ping_status = models.CharField(blank=True, max_length=1, editable=False)
The field will contains one letter:
G = OK, R = KO, O = Suspect

I created and image corresponding to each letter (G => green.png etc)
because I want the image be displayed in the changelist page instead
of the letter.

Can anybody tell me which method in ModelAdmin to override to have a
hook to chang the used widget?

-- 
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: Upload code from development server to local server

2010-05-14 Thread Alessandro Pasotti
2010/5/14 Archidjango 

> Hey all,
>
> I'm a little confused, but I guess that's normal being a real
> newbie :-) .
>
> I tried to upload code written on my development server to a "real"
> web server.
>
> I uploaded the code through ftp and made the url-forward, tested an
> dummy "index.html" so there's no problem on that side. The connection
> seems to be fine.
>
> However, the server (?) does not seem to recognize the python code.
> The first line I get on a browser when navigating to the website's url
> is the following:
>
> {% extends "xyz.html" %} {% load i18n %} {% block title %}{% trans
> "Calculate" %}{% endblock %} {% block media %} {% endblock %} {% block
> content %}
>
> On my development server the whole thing works fine, but I don't
> exactly know what to do to make the online version work as well.
>
> Does anyone have an idea on how to solve this problem?
>


Hi,

you don't give much details about your intended server setup...
just to be sure, did you read the django manual page on deployment ?

Here is the link, as you will see, you have many different possibilities,
mod_wsgi being the recommended one:

docs.djangoproject.com/en/1.1/howto/deployment/#howto-deployment-index

-- 
Alessandro Pasotti
w3:   www.itopen.it

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



Upload code from development server to local server

2010-05-14 Thread Archidjango
Hey all,

I'm a little confused, but I guess that's normal being a real
newbie :-) .

I tried to upload code written on my development server to a "real"
web server.

I uploaded the code through ftp and made the url-forward, tested an
dummy "index.html" so there's no problem on that side. The connection
seems to be fine.

However, the server (?) does not seem to recognize the python code.
The first line I get on a browser when navigating to the website's url
is the following:

{% extends "xyz.html" %} {% load i18n %} {% block title %}{% trans
"Calculate" %}{% endblock %} {% block media %} {% endblock %} {% block
content %}

On my development server the whole thing works fine, but I don't
exactly know what to do to make the online version work as well.

Does anyone have an idea on how to solve this problem?

Thanks for your advise everyone!

-- 
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 (when saving): manipulating a parent field based on an inline object's field

2010-05-14 Thread TeenSpirit83
I have a Parent model having some Child objects edited as an inline in
the change view of the Parent.
I want to write some data in a Parent's field which is a calculation
based on some other field of all its Child objects.
I think i have to intercept child data in the save_model or
save_formset methods of ParentAdmin class but I'm not sure which one
of the two I have to modify and what is the way to do it.
How would you do it?

I'd prefer to don't show the Parent's calculated field in the page.
This means I would not include this field in the MyParentAdminForm
class

Thank you!

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

2010-05-14 Thread Tom Evans
On Thu, May 13, 2010 at 7:31 PM, Daniel Roseman  wrote:
>
>
> On May 13, 5:35 pm, Peter Herndon  wrote:
>> On May 13, 2010, at 10:29 AM, TallFurryMan wrote:
>>
>> > Hello Django users,
>>
>> > Is there a particular reason why using a related OneToOneField raises
>> > DoesNotExist instead of returning None?
>>
>> Any query you make that is supposed to return one or more instances, that 
>> instead cannot find any results, returns a DoesNotExist.
>
> Not true - a .filter() query returns an empty QuerySet if no results
> are found. However a .get() query does raise DoesNotExist if it
> doesn't find anything - which is the exact equivalent of a
> OneToOneField lookup.

To get super pedantic, he said 'any query that is supposed to return
one or more instances' would raise a DoesNotExist. You countered with
a .filter() query, which returns 0 or more instances.

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.



I need help

2010-05-14 Thread Hussain Deikna
Hi,
 I plan to start writing my web page and I decide to use django and sqlite3
, my web page is very simple it is look like :
 1- homepage a main page for public 'main page'.
 2- user login and it will display special information to every to group of
users
 3- admen side.
I need help in part 2 which django application I have to use?
thank you

-- 
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: HttpResponseRedirect(request.path) after request.POST issue

2010-05-14 Thread Tom Evans
On Thu, May 13, 2010 at 6:11 PM, marty3d  wrote:
> Thanks, that's a shame...
> So I'm now trying to do the request.POST stuff in a view instead.
> Since the idea is to have the voting app as decoupled as possible, is
> there a slick way to pass, perhaps the whole object in this case, but
> at least the name of the model or similar together with the post?
>
> Thanks!
> /Martin
>

I can think of three options off the top of my head:

1) Have the voting app always submit to one view, regardless of the
current view. The voting app form could include a 'next' parameter,
indicating where to send the user back to.

2) Write the form processing code as a middleware. If you dont want
every page to handling posting this voting app form, use the
decorator_from_middleware adapter to turn your middleware into
something you can decorate specific views with.

3) Handle posts from the voting app with AJAX, always posting to the
same page, and updating the displayed content in the page when done.

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: Using extra() to add table alias

2010-05-14 Thread michael luger

this might be a django bug .

a workaround using a view for the second usage worked for me . in your
case something like:

create view category_parent as select * from category;

category_list =
Category.objects.all().extra(tables=['category_parent'],
where=['category.lft BETWEEN category_parent.lft AND
category_parent.rgt'])

On 13 Mai, 22:23, Austin Gabel  wrote:
> I am trying to use the ORM to build the following query:
> """SELECT * FROM category AS node, category AS parent WHERE node.lft BETWEEN
> parent.lft AND parent.rgt"""
>
> I am attempting to create the table aliases using .extra() but I'm having a
> bit of difficulty.  I have left out the where statements in order to reduce
> complexity while troubleshooting this issue.  My current code looks like
> this.
> category_list = Category.objects.all().extra(tables=['category'])
>
> The way I understand the documentation [1] is if a table is listed in the
> tables argument that already exists in the query, it will add the table with
> a generic alias. However, it is simply ignoring the additional table.  This
> is the SQL that is produces.
>
> ('SELECT "category"."id", "category"."lft", "category"."rgt",
> "category"."tree_id", "category"."depth", "category"."name" FROM "category"
> ORDER BY "category"."name" ASC', ())
>
> Is this not the correct way to go about adding a table alias?  Am I just
> missing something or am I way off track here?
>
> [1]http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-sele...
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Using extra() to add table alias

2010-05-14 Thread michael luger

this might be a django bug .

a workaround using a view for the second table usage worked for me .
in your case something like:

create view category_parent as select * from category;

category_list =
Category.objects.all().extra(tables=['category_parent'],
where=['category.lft BETWEEN category_parent.lft AND
category_parent.rgt'])


On 13 Mai, 22:23, Austin Gabel  wrote:
> I am trying to use the ORM to build the following query:
> """SELECT * FROM category AS node, category AS parent WHERE node.lft BETWEEN
> parent.lft AND parent.rgt"""
>
> I am attempting to create the table aliases using .extra() but I'm having a
> bit of difficulty.  I have left out the where statements in order to reduce
> complexity while troubleshooting this issue.  My current code looks like
> this.
> category_list = Category.objects.all().extra(tables=['category'])
>
> The way I understand the documentation [1] is if a table is listed in the
> tables argument that already exists in the query, it will add the table with
> a generic alias. However, it is simply ignoring the additional table.  This
> is the SQL that is produces.
>
> ('SELECT "category"."id", "category"."lft", "category"."rgt",
> "category"."tree_id", "category"."depth", "category"."name" FROM "category"
> ORDER BY "category"."name" ASC', ())
>
> Is this not the correct way to go about adding a table alias?  Am I just
> missing something or am I way off track here?
>
> [1]http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-sele...
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Tree view me

2010-05-14 Thread cyrux cyrux
I have a simple task to accomplish. I have some hierarchal data in my
database which needs to be displayed in a UI. It needs to be simple
and preferably in a expandable tree format (although a non -expandable
should work as well). This is what I am looking for
http://source.mihelac.org/x/treetable/tests/example2.html#

I have been looking django since last week and I haven't gone
anywhere. I have looked at a couple of extensions , but I am not sure
if they would work. So , is it possible to achieve some thing like the
above link in django ? I have looked into django-mptt and django-
treemneu but seems consuing. I have never really worked on front end
languages like HTML , PHP , so the template part of django confuses
me. There is so much of stuff happening behind the scenese that
confuses me. If somebody can tell me if this is possible, i can spend
may be a day or more looking into it, else I will probably go for php
stuff

-- 
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 Simple Example

2010-05-14 Thread Jani Monoses




if model._meta.app_label == 'myapp' and model._meta.object_name ==
'ModelInDatabase2Name':

That is - instead of just checking the app, check the app and the
model name. Install the router, and any query involving
ModelInDatabase2Name will be directed to the 'other' database.


It would be helpful to add this to the documentation, as only routing 
certain models to a different DB may be quite frequent.
I found this out this week by looking at the db sources and after 
finding nothing in the docs.


Trying to import models.py from the app in the router module leads to 
problems as the router is set up at db module initialization, so db and 
db.util try to import each other without success. Mentioning this could 
save some time for those trying db routing for the first time.


Jani

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