Re: count resulting rows in sliced valuesqueryset

2012-11-23 Thread Peter of the Norse
On Nov 21, 2012, at 3:53 AM, ?manu* wrote:

> Suppose I have a queryset qs. For paginating purposes I need to do something 
> like:
> 
> count = qs.count()
> qs = qs[0:100]
> 
> Unfortunately this executes the query twice, which I don't want. 

Are you sure? This is such a common pattern that I suspect that it’s not slower 
than making it into one query. I ran some tests on the slowest query I have, 
and the two statements were faster than trying to combine them. 0.2 + 1.5 sec 
vs. 1.9 sec.

> I can use postgresql windowing function like that:
> 
> qs = q.extra(select = {'count': 'COUNT(*) OVER()'})
> 
> to get the 'count' attribute on every object. So far this is very nice. The 
> problem is that my queryset qs is actually a ValuesQueryset, i.e. a queryset 
> build with .values(...).annotate(...). In this case the extra select field is 
> ignored (as reported in the documentation). This makes sense because even in 
> postgres it seems not possible to mix window functions with "group by" 
> clauses. The solution with raw SQL is the use of a subquery. I can get the 
> correct results with the following query, where I enclose the sql produced by 
> django in a subquery:
> 
> sql = 'SELECT COUNT(*) OVER() , subquery.* FROM (%s) AS subquery' % qs.query
> 
> Now the questions:
> 
> 1. in this snippet qs.query is converted to string. The documentation says 
> that parameters in the resulting query string are not correctly escaped, so 
> maybe I should take care of SQL injection? How do I get correct escaping of 
> parameters?

You don't. The problem is qs.query is constructed for your convenience, it’s 
not what’s passed to the database. For a query like User.objects.fiter(id=5), 
the underling DB call looks like cursor.execute("SELECT * FROM user WHERE id = 
%s", (5,)). That is, the SQL has placeholders for the values, and the values 
are passed separately. Django doesn't actually escape the values, it just lets 
the DB backend do it. It’s much safer and a little faster to do it that way. 
Look at qs.query.sql_with_params()

> 2. Is it possible to re-attach the sql statement to my ValuesQuerySet? To 
> keep the rest of the code unchanged, I need to modify qs so that it executes 
> the new raw query. However I don't see how to construct a ValuesQueryset with 
> a raw SQL code...

sql, params = qs.query.sql_with_params()
s = ValuesQuerySet.objects.raw('SELECT COUNT(*) OVER() , subquery.* FROM 
('+sql+') AS subquery', params);
see https://docs.djangoproject.com/en/1.4/topics/db/sql/

Let me know if that works.

Peter of the Norse
rahmc...@radio1190.org



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



Re: Re: How can I contrast two date-time type variables in template layer?

2012-11-23 Thread Dae James
Soga. Thank you very much.




Dae James

From: smcoll
Date: 2012-11-24 02:02
To: django-users
Subject: Re: How can I contrast two date-time type variables in template layer?
The 'timesince' filter (based on django.utils.timesince) doesn't return a 
datetime.timedelta object, but a formatted string.  So it would be hard to 
compare the resulting string with anything.  i think you're going to need to do 
one of the following:
do the comparison in your view and add the result (true/false) to the context
add the cutoff date to the context and compare the two datetime objects in your 
template
write/find a templatetag or filter that can do what you need



On Friday, November 23, 2012 12:36:27 AM UTC-6, Dae_James wrote:
For example, art_time is a date-time type.
As we know, {{ art_time|timesince }} return the time since art_time to now. 
However, I want to know how to judge whether the result is within 24 hours.
Shortly, how to know whether art_time is today or the day before today in 
template layer?
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/EmGMHChbbLkJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

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



Re: Django 1.6.0 over python 3: mysql?

2012-11-23 Thread Russell Keith-Magee
Hi,

The short answer is that MySQLdb is outside the control of the Django
project. Django itself is now Python 3 compatible. The compatibility of
other libraries is up to their respective maintainers.

That said, I doubt you'll regret the move to PostgreSQL :-)

Yours,
Russ Magee %-)

On Sat, Nov 24, 2012 at 5:43 AM, ajendrex  wrote:

> I decided to use postgresql and move on :)
>
>
> On Friday, November 23, 2012 11:02:10 AM UTC-3, ajendrex wrote:
>>
>> Hello,
>>
>> I'm new to django and I'm going directly to use it over python 3 (I have
>> been using python 3 for mor than one year). However, the MySQLdb library
>> doesn't support python 3 yet. Is there a way of connecting django to mysql
>> over python3? If not, any plan to get it in the near future?
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/n1hMGSYAR74J.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Announce Short URL Generator [short_url]

2012-11-23 Thread Alir3z4
Hello,

I've released an python package that is a Short URL Generator.

I thought would be useful for other people to use it with django or any 
other related topic.

It's available on github[1], pypi[2].

[1]: http://alir3z4.github.com/short_url
[2]: http://pypi.python.org/pypi/short_url

Regards,
Alireza Savand

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



Re: Invalid properties don't throw errors?

2012-11-23 Thread Tim Chase
On 11/23/12 15:31, Aaron C. de Bruyn wrote:
> Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
 u = User.objects.get(pk=1)
 u.user = 'test'

> 
> No error.  It should be 'u.username'.

This is a Python thing, not limited to Django, and fully expected:

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyClass(object): pass
...
>>> c = MyClass()
>>> c.doesnotexist = 42

Barring some particular situations (you may want to read up on
__slots__), you can dynamically add any property you want to an
object/class.  Python is less forgiving if you *read* nonexistent
properties:

>>> print c.no_property_here
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'MyClass' object has no attribute 'no_property_here'


-tkc







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



Re: Django 1.6.0 over python 3: mysql?

2012-11-23 Thread ajendrex
I decided to use postgresql and move on :)

On Friday, November 23, 2012 11:02:10 AM UTC-3, ajendrex wrote:
>
> Hello,
>
> I'm new to django and I'm going directly to use it over python 3 (I have 
> been using python 3 for mor than one year). However, the MySQLdb library 
> doesn't support python 3 yet. Is there a way of connecting django to mysql 
> over python3? If not, any plan to get it in the near future?
>

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



Invalid properties don't throw errors?

2012-11-23 Thread Aaron C. de Bruyn
I'm stumped.

I have a Django project that's fairly far along--I'm able to use it 
internally.

A few days ago while trying to debug a function, I noticed I was settings a 
property incorrectly.

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> u = User.objects.get(pk=1)
>>> u.user = 'test'
>>> 

No error.  It should be 'u.username'.

So I tried a few more.

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> u = User.objects.get(pk=1)
>>> u.sdbgnois74gn = 'test'
>>> 

No error is thrown for trying to set an invalid property.

I tried blowing away my virtualenv and reinstalling.  Same issue.

Passing invalid parameters while creating a new object throws errors, but 
not after the object is created.

>>> django.VERSION
(1, 4, 2, 'final', 0)
>>> c = Company(doesnotexist='123')
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/aaron/.virtualenvs/tapp/local/lib/python2.7/site-packages/django/db/models/base.py",
 
line 367, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" 
% kwargs.keys()[0])
TypeError: 'doesnotexist' is an invalid keyword argument for this function
>>> c = Company(name='123')
>>> c.doesnotexist = '123'
>>>

I have never witnessed this behavior before in python.  Any pointers on 
where I should start digging?

-A

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



Re: memory leak? Am I taking crazy pills?

2012-11-23 Thread akaariai


On 22 marras, 08:27, Dan Ancona  wrote:
> python 2.7.3, django 1.4.2
>
> Our app (a fairly simple tastypie API that runs some machine learning foo on 
> mongodb records) is deployed to heroku and is leaking memory at a pretty good 
> clip. Hitting heroku memory errors after about an hour or two, under 
> significant load.
>
> Wandered through some various profiling options and eventually started to get 
> suspicious of tastypie. So I tried ripping that out. And then everything 
> else, until I finally got down to a django view that has nothing but this in 
> it:
>
> def stack(request):
>    gc.set_debug(gc.DEBUG_LEAK)
>    print "Uncollectable garbage", gc.garbage
>    return HttpResponse('hi')

If you set gc.DEBUG_LEAK then the GC will not free anything, instead
it will append garbage to gc.garbage. So, getting everything into
gc.garbage is expected in that case.

You will want to remove the gc.set_debug() call.

Here is an example without the call:

import gc
from django.http import HttpResponse

# Objects which have __del__ defined and are part of reference cycle
will be uncollectable.
class A(object):
def __del__(self):
pass
class B(object):
pass

def stack(request):
a = A()
b = B()
# Lets create a cycle
a.b = b
b.a = a
print(gc.garbage)
return HttpResponse('hi')


Load the view a couple of times and you will see garbage accumulating.
It will contain only the A objects - they are uncollectable because of
the __del__ method.

 - Anssi

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



Re: Email notifications app

2012-11-23 Thread Brad Pitcher
Checkout django drip:
https://github.com/zapier/django-drip
On Nov 23, 2012 7:22 AM, "Arnaud BRETON"  wrote:

> Hi everybody,
>
> I'm looking for a powerful third-app for Django to manage time-driven
> email notifications.
>
> I found django-notifications (
> https://github.com/jtauber/django-notification) but it seems not
> maintained anymore..
>
> Thanks !
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/UeHxWh5cp4kJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Editing model instance

2012-11-23 Thread Sandeep kaur
On Fri, Nov 23, 2012 at 7:25 PM, Victor Rocha  wrote:
> For starters, I see more than one thing wrong with your code. I hope thats
> not the one your actually using and it was just a typo when you asked the
> question.
> + jform = editJobForm(request.POST, instance=job) # job has not being
> defined.
> Also when you instantiate your form, you want to use and instance of the
> class your want to use, for instance. gi

> clientjob = ClientEditJob.objects.get(job_id =query)
> job = EditJob.objects.get(job_id=query)
>
If I do this I won't get previously filled values of ClientJob table
which I need for editing. ClientEditJob table is empty.

> Right now you using this: clientjob = ClientJob.objects.get(job_id = query).
> ClientJob is not a model for any of the two forms you are using.
>
I think you haven't understood what I want. I don't say my code is
correct, Because if it would be, I would have got my results. Please
help me change it to correct one.
What I want to do :
Get instance of one table, which after editing get saved to some other table.
What I get :
I get values of one table and after editing it get saved to the same table. :(

-- 
Sandeep Kaur
E-Mail: mkaurkha...@gmail.com
Blog: sandymadaan.wordpress.com

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



Questions about unicode

2012-11-23 Thread Santiago Basulto
Hey guys, i'm kind of confused here...

If I get data from a request, say:

request.GET.get("something") or request.POST.get("something")

Is it automatically being encoded based on the Encoding of the
request? Or I should take care of it explicitly?

Thank you.

--
Santiago Basulto.-

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



Re: How can I contrast two date-time type variables in template layer?

2012-11-23 Thread smcoll
The 'timesince' filter (based on django.utils.timesince) doesn't return a 
datetime.timedelta object, but a formatted string.  So it would be hard to 
compare the resulting string with anything.  i think you're going to need 
to do one of the following:

   - do the comparison in your view and add the result (true/false) to the 
   context
   - add the cutoff date to the context and compare the two datetime 
   objects in your template
   - write/find a templatetag or filter that can do what you need



On Friday, November 23, 2012 12:36:27 AM UTC-6, Dae_James wrote:
>
> For example, art_time is a date-time type.
> As we know, {{ art_time|timesince }} return the time since art_time to 
> now. However, I want to know how to judge whether the result is within 24 
> hours.
> Shortly, how to know whether art_time is today or the day before today in 
> template layer?
>

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



having some validation logic in abstract class

2012-11-23 Thread Emmanuel Jannetti
Hi all, 

The question is how to add some validation statement in an upper/abstract 
class against all instances of subclasses.

here is the model

*class UpperAbstract(models.Model):*
*
*
*  def verifyUnique(value):*
*if value:*
*  len(UpperAbstract.objects.filter(myuniquefield=value)) > 0:*
* raise ValidationError(...)*
*
*
*  myuniquefield = CharField(max_length=15, 
blank=True,validators=[verifyUnique]))*
*
*
*  class Meta:*
* abstract = True*
*
*
*class Foo(UpperAbstract):*
*  myFoofield = CharField(max_length=15)*
*
*
*class Bar(UpperAbstract):*
*  myBarfield = CharField(max_length=15)*


Validation and store of any instance of *Foo* or *Bar* is failing as *
UpperAbstract* do not have *objects* attribute.
I can imagine why  but my question is then how to achieve this type of 
validation ? 

PS : my first goal was to be able to define field as 'unique if not None'.

thank in advance 
Regards
manu


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



overwrite field value in subclasses

2012-11-23 Thread Emmanuel Jannetti
Hi all,

One piece of my model is as follow :

*class UpperAbstract(models.Model):*
*  CHOICE_A = 0*
*  CHOICE_B = 1*
*  **CHOICE_C = 2*
*  myfield = 
models.PositiveSmallIntegerField(choices=((CHOICE_A,'A'),(CHOICE_B,"B")**
,(CHOICE_C,"C")**),blank=False)*
*  class Meta:*
* abstract = True*
*
*
*class Foo(UpperAbstract):*
*  myfield = UpperAbstract.CHOICE_A*



I am expecting any instance of Foo being created, to have 'myfield' always 
and "automatically" set to UpperAbstract.CHOICE_A
In my test the created object as null value and saving it is refused on 
IntegrityError because 'myfield' cannot be None

thank in advance for any help.
regards

manu





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



Email notifications app

2012-11-23 Thread Arnaud BRETON
Hi everybody,

I'm looking for a powerful third-app for Django to manage time-driven email 
notifications.

I found django-notifications (https://github.com/jtauber/django-notification) 
but 
it seems not maintained anymore..

Thanks !

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



Re: memory leak? Am I taking crazy pills?

2012-11-23 Thread Dan Ancona
Sorry, forgot to mention. Debug is definitely set to False!

On Nov 22, 2012, at 7:44 AM, Tom Evans wrote:

> On Thu, Nov 22, 2012 at 6:27 AM, Dan Ancona  wrote:
>> python 2.7.3, django 1.4.2
>> 
>> Our app (a fairly simple tastypie API that runs some machine learning foo on 
>> mongodb records) is deployed to heroku and is leaking memory at a pretty 
>> good clip. Hitting heroku memory errors after about an hour or two, under 
>> significant load.
>> 
>> Wandered through some various profiling options and eventually started to 
>> get suspicious of tastypie. So I tried ripping that out. And then everything 
>> else, until I finally got down to a django view that has nothing but this in 
>> it:
>> 
>> def stack(request):
>>   gc.set_debug(gc.DEBUG_LEAK)
>>   print "Uncollectable garbage", gc.garbage
>>   return HttpResponse('hi')
>> 
>> And even that, after a couple reloads, dumps a huge mess, the beginning of 
>> which is below. Looks like the whole heap.
>> 
>> Any idea what might be going on here or what my next steps are?
>> 
> 
> Is settings.DEBUG true? Expected behaviour.
> 
> 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-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Django 1.6.0 over python 3: mysql?

2012-11-23 Thread ajendrex
Hello,

I'm new to django and I'm going directly to use it over python 3 (I have 
been using python 3 for mor than one year). However, the MySQLdb library 
doesn't support python 3 yet. Is there a way of connecting django to mysql 
over python3? If not, any plan to get it in the near future?

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



Re: Django 1.4: TypeError: get_db_prep_value() got an unexpected keyword argument 'connection'

2012-11-23 Thread Felix Guo
I also have this problem, I don't have any custom field and still see this 
error. 

I have completely remove all previous django, but after I install latest 
django 1.4.2, I can still find your function: get_db_prep_save appeared in  
/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py  
line 872. 

Are you sure your latest installation package completely remove the 
function?

Thank you

Felix Guo

On Sunday, April 8, 2012 1:31:17 PM UTC+10, Russell Keith-Magee wrote:
>
> Hi,
>
> What you've hit here is the end of the deprecation cycle for code that 
> doesn't support multiple databases.
>
> In Django 1.2, we introduced multiple database support; in order to 
> support this, the prototype for get_db_preb_lookup() and 
> get_db_prep_value() was changed.
>
> For backwards compatibility, we added a shim that would transparently 
> 'fix' these methods if they hadn't already been fixed by the developer.
>
> In Django 1.2, the usage of these shims raised a 
> PendingDeprecationWarning. In Django 1.3, they raised a DeprecationWarning.
>
> Under Django 1.4, the shim code was been removed -- so any code that 
> wasn't updated will now raise errors like the one you describe.
>
> All the core Django fields should have been updated to use the new 
> signature, so if you're seeing errors, it's probably because of a custom 
> field that you're using that needs to be updated. As far as I can make out, 
> Django's default ImageField shouldn't have this problem (it doesn't even 
> have db_prep_* methods, because there's nothing database specific about the 
> storage of FileFields).
>
> If you can reproduce this on a project that only uses Django's built-in 
> field types, then this is a bug in Django that needs to be addressed.
>
> Yours
> Russ Magee %-)
>
>
> On Saturday, 7 April 2012 at 12:03 PM, xthepoet wrote:
>
> > This was working fine for my Ubuntu 10.04LTE system with Django
> > 1.3.1. It seems broken now in 1.4.
> > 
> > In Django 1.4, I get this error TypeError: get_db_prep_value() got an
> > unexpected keyword argument 'connection' when saving an image to an
> > ImageField.
> > 
> > System (installed from Ubuntu Lucid repository packages):
> > Django 1.4
> > Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
> > 
> > The model field is defined as: origin_image =
> > models.ImageField(upload_to='images/origin')
> > The offending call is: obj.origin_image.save(fbFileName,
> > ContentFile(input_file.getvalue()))
> > 
> > Traceback (most recent call last):
> > File "/home/seeker/src/ceeq/seekerapp/management/commands/
> > addUser.py", line 100, in addPhotos
> > obj.origin_image.save(fbFileName,
> > ContentFile(input_file.getvalue()))
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/fields/files.py", line 95, in save
> > self.instance.save()
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/base.py", line 463, in save
> > self.save_base(using=using, force_insert=force_insert,
> > force_update=force_update)
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/base.py", line 551, in save_base
> > result = manager._insert([self], fields=fields,
> > return_id=update_pk, using=using, raw=raw)
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/manager.py", line 203, in _insert
> > return insert_query(self.model, objs, fields, **kwargs)
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/query.py", line 1576, in insert_query
> > return query.get_compiler(using=using).execute_sql(return_id)
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/sql/compiler.py", line 909, in execute_sql
> > for sql, params in self.as_sql():
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/sql/compiler.py", line 872, in as_sql
> > for obj in self.query.objs
> > File "/usr/local/lib/python2.6/dist-packages/Django-1.4-py2.6.egg/
> > django/db/models/fields/__init__.py", line 292, in get_db_prep_save
> > prepared=False)
> > TypeError: get_db_prep_value() got an unexpected keyword argument
> > 'connection'
> > 
> > This problem was also reported on the django-celery board:
> > https://github.com/ask/celery/issues/624
> > But I've realized that for me, it's not a celery issue.
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> > To post to this group, send email to 
> > django...@googlegroups.com(mailto:
> django...@googlegroups.com ).
> > To unsubscribe from this group, send email to 
> django-users...@googlegroups.com  (mailto:
> 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.
T

building database

2012-11-23 Thread garlicdud
Hello everyone, in 2006 I created an application with VBA (access from 
microsoft). I do life access but I can't dig windows. So I switched to 
linux and I love it. I want to move with it in the same direction and learn 
to develop database infrastructure. is-there an open source program similar 
to access I can use under Linux ?

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



Re: Editing model instance

2012-11-23 Thread Victor Rocha
This would be the code I would like you to try:

def editjob(request): 
clientjob = ClientEditJob.objects.get(job_id =query) 
#adjust query as needed
job = EditJob.objects.get(job_id=query)#adjust query as 
needed
if request.method == "POST": 
jform = editJobForm(request.POST, instance=job) 
sform = editClientJobForm(request.POST, 
instance=clientjob) 
if jform.is_valid() and sform.is_valid(): 
jform.save() 
sform.save() 
return 
render_to_response('tcc/succes.html',context_instance=RequestContext(request)) 
else: 
jform = editJobForm(instance=job) 
sform = editClientJobForm(instance=clientjob) 
return render_to_response('tcc/edit_job.html', {'jform': 
jform,'sform':sform},context_instance=RequestContext(request)) 

Thank you,
Victor Rocha
RochApps 

On Friday, November 23, 2012 8:55:06 AM UTC-5, Victor Rocha wrote:
>
> For starters, I see more than one thing wrong with your code. I hope thats 
> not the one your actually using and it was just a typo when you asked the 
> question.
> + jform = editJobForm(request.POST, instance=job) # job has not 
> being defined.
> Also when you instantiate your form, you want to use and instance of the 
> class your want to use, for instance.
> clientjob = ClientEditJob.objects.get(job_id =query) 
> job = EditJob.objects.get(job_id=query)
>
> Right now you using this: clientjob = ClientJob.objects.get(job_id = 
> query). ClientJob is not a model for any of the two forms you are using.
>
> Let me know if I was of any help,
> Victor Rocha
> RochApps 
>
>
> On Thursday, November 22, 2012 5:59:11 AM UTC-5, sandy wrote:
>>
>> I edit value of a table using model instance, however after editing I 
>> want the values to be saved in some other table with same structure. 
>> For this to happen I have used following code in views.py : 
>>
>> def editjob(request): 
>> clientjob = ClientJob.objects.get(job_id = query) 
>> if request.method == "POST": 
>> jform = editJobForm(request.POST, instance=job) 
>> sform = editClientJobForm(request.POST, 
>> instance=clientjob) 
>> if jform.is_valid() and sform.is_valid(): 
>> jform.save() 
>> sform.save() 
>> return 
>> render_to_response('tcc/succes.html',context_instance=RequestContext(request))
>>  
>>
>> else: 
>> jform = editJobForm(instance=job) 
>> sform = editClientJobForm(instance=clientjob) 
>> return render_to_response('tcc/edit_job.html', {'jform': 
>> jform,'sform':sform},context_instance=RequestContext(request)) 
>>
>> where : 
>> class editJobForm(forms.ModelForm): 
>> class Meta : 
>> model = EditJob 
>> exclude= ['client','job_no','id'] 
>>
>> class editClientJobForm(forms.ModelForm): 
>>
>> class Meta : 
>> model = ClientEditJob 
>> exclude= ['job'] 
>>
>> However this code saves the value in same instance itself. What I want 
>> is to get old values from table: Job and ClientJob and then after 
>> editing get saved in tables: EditJob and ClentEditJob. 
>> Is this possible? Your help will be appreciated. 
>> Thank you. 
>>
>> -- 
>> Sandeep Kaur 
>> E-Mail: mkaur...@gmail.com 
>> Blog: sandymadaan.wordpress.com 
>>
>

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



Re: Editing model instance

2012-11-23 Thread Victor Rocha
For starters, I see more than one thing wrong with your code. I hope thats 
not the one your actually using and it was just a typo when you asked the 
question.
+ jform = editJobForm(request.POST, instance=job) # job has not 
being defined.
Also when you instantiate your form, you want to use and instance of the 
class your want to use, for instance.
clientjob = ClientEditJob.objects.get(job_id =query) 
job = EditJob.objects.get(job_id=query)

Right now you using this: clientjob = ClientJob.objects.get(job_id = 
query). ClientJob is not a model for any of the two forms you are using.

Let me know if I was of any help,
Victor Rocha
RochApps 


On Thursday, November 22, 2012 5:59:11 AM UTC-5, sandy wrote:
>
> I edit value of a table using model instance, however after editing I 
> want the values to be saved in some other table with same structure. 
> For this to happen I have used following code in views.py : 
>
> def editjob(request): 
> clientjob = ClientJob.objects.get(job_id = query) 
> if request.method == "POST": 
> jform = editJobForm(request.POST, instance=job) 
> sform = editClientJobForm(request.POST, 
> instance=clientjob) 
> if jform.is_valid() and sform.is_valid(): 
> jform.save() 
> sform.save() 
> return 
> render_to_response('tcc/succes.html',context_instance=RequestContext(request))
>  
>
> else: 
> jform = editJobForm(instance=job) 
> sform = editClientJobForm(instance=clientjob) 
> return render_to_response('tcc/edit_job.html', {'jform': 
> jform,'sform':sform},context_instance=RequestContext(request)) 
>
> where : 
> class editJobForm(forms.ModelForm): 
> class Meta : 
> model = EditJob 
> exclude= ['client','job_no','id'] 
>
> class editClientJobForm(forms.ModelForm): 
>
> class Meta : 
> model = ClientEditJob 
> exclude= ['job'] 
>
> However this code saves the value in same instance itself. What I want 
> is to get old values from table: Job and ClientJob and then after 
> editing get saved in tables: EditJob and ClentEditJob. 
> Is this possible? Your help will be appreciated. 
> Thank you. 
>
> -- 
> Sandeep Kaur 
> E-Mail: mkaur...@gmail.com  
> Blog: sandymadaan.wordpress.com 
>

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