admin css

2012-03-04 Thread Mike Dewhirst
I would like to adjust the admin app's base.css. Nothing outrageous. I 
just want to change all the #999 color values to something a little bit 
darker so screen text is slightly easier to see.


I could write a python script to do that but it feels wrong.

I tried locating somewhere in my project to put my own adjusted base.css 
but can't find exactly where to put it.


collectstatic gets base.css from contrib.admin and puts it into 
/static/admin/css but anything in my project gets put straight into 
/static/css


Is there a simple way to avoid editing the contrib.admin base.css?

Thanks

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-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: equivalent of flask's flash() in django

2012-03-04 Thread Daniel Arbanas
On Sun, Mar 4, 2012 at 8:12 PM, Bolang  wrote:

> Hi all,
> What is the equivalent of flask's flash()[1] in django?
>
> Thanks
>
> [1]
> http://flask.pocoo.orghttps://docs.djangoproject.com/en/dev/ref/contrib/messages//
> **docs/patterns/flashing/ 


Hi,

https://docs.djangoproject.com/en/dev/ref/contrib/messages/

d.

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



Haystack Solr Error

2012-03-04 Thread coded kid
I'm trying to rebuild_index, so after inputting manage.py rebuild-
index , I'm getting:

Removing all documents in your index because you said so.
fail to clear Solr index: [Errno 10061] No connection could be made
because the target
machine actively refused it.

What I'm I doing wrong?

-- 
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: Security: How to destroy sessions for a user

2012-03-04 Thread Mr. Gerardo Gonzalez Cruz
You need check session always into your database to manage user sessions.
When change a password you need a simple update over session table, then
over every request in your site you need check if you password had a
change, if yes the user session set a null. Basically you need polling to
database on every request.

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

2012-03-04 Thread Piotr Zalewa

On 03/04/12 20:06, Daniel Hilton wrote:

On 4 March 2012 18:35, Jani Tiainen  wrote:

I've been very happy with django-rest-framework.

I think there exists at least django-piston to do the same.


The other one to look at is django-tastypie - I've used it twice now
in anger and been really happy with it plus the rate of development /
improvement I've seen.

Cheers,
Dan



I'm writing REST with tastypie right now. I do like the way it is done. 
Community on IRC is very responsive, docs are good, examples and such.




And you can write it also "manually". Since REST is just architectural
specification and doesn't involve any special magic.

On Sun, Mar 4, 2012 at 8:13 PM, Bharath Mundlapudi
wrote:


Dear Django Users and Authors,

I am wondering if there are any best practices or better way to write REST
based apps on top of Django. I was using version 1.1 and not followed recent
advancements. Can you kindly point me to links or references from your
experience.

Preferably out-of-the-box solutions.

-Bharath

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



--

Jani Tiainen

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



equivalent of flask's flash() in django

2012-03-04 Thread Bolang

Hi all,
What is the equivalent of flask's flash()[1] in django?

Thanks

[1]http://flask.pocoo.org/docs/patterns/flashing/

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

2012-03-04 Thread Mo Mughrabi
I recommend django-piston, we've been using it and it's great and highly
capable

On Sun, Mar 4, 2012 at 9:13 PM, Bharath Mundlapudi wrote:

> Dear Django Users and Authors,
>
> I am wondering if there are any best practices or better way to write REST
> based apps on top of Django. I was using version 1.1 and not followed
> recent advancements. Can you kindly point me to links or references from
> your experience.
>
> Preferably out-of-the-box solutions.
>
> -Bharath
>
> --
> 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.



Re: Django REST

2012-03-04 Thread Daniel Hilton
On 4 March 2012 18:35, Jani Tiainen  wrote:
> I've been very happy with django-rest-framework.
>
> I think there exists at least django-piston to do the same.

The other one to look at is django-tastypie - I've used it twice now
in anger and been really happy with it plus the rate of development /
improvement I've seen.

Cheers,
Dan

>
> And you can write it also "manually". Since REST is just architectural
> specification and doesn't involve any special magic.
>
> On Sun, Mar 4, 2012 at 8:13 PM, Bharath Mundlapudi 
> wrote:
>>
>> Dear Django Users and Authors,
>>
>> I am wondering if there are any best practices or better way to write REST
>> based apps on top of Django. I was using version 1.1 and not followed recent
>> advancements. Can you kindly point me to links or references from your
>> experience.
>>
>> Preferably out-of-the-box solutions.
>>
>> -Bharath
>>
>> --
>> 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.
>
>
> --
>
> Jani Tiainen
>
> --
> 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.



-- 
Dan Hilton

www.twitter.com/danhilton
www.DanHilton.co.uk


-- 
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: GeoDjango distance queryset filter with distance value stored within model

2012-03-04 Thread Jani Tiainen
I think you can only achieve that currently by using queryset extra()
method.

You should open a ticket and preferably create a standard geodjango
testcase for that. It could be also possible that not all gis backends
support that kind of a behavior.

On Sat, Mar 3, 2012 at 6:47 PM, Daniel Gerzo  wrote:

> Hello guys,
>
> I have an Order model, that has an origin PointField and a range
> IntegerField. Furthermore, there is an UserProfile model, which has a
> geo_location PointField. Now, I have an User instance, user. I want to
> select all Orders, whose distance between Order.origin and
> user.userprofile.geo_location is less then the value (meters) in the
> Order.range model field.
>
> So again, simplified models:
>
> class Order(models.Model):
>origin = models.PointField()
>range = models.IntegerField(blank=**True, default=1)
>
> class UserProfile(models.Model):
>geo_location = models.PointField()
>
>
> I've got this working (passing the distance statically):
>
> >>> Order.objects.filter(origin__**distance_lte=(user.profile.**geo_location,
> D(m=3000)))
>
> My next (unsuccessful) try was to use an F() expression to use the value
> from the Order.range field:
>
> >>> Order.objects.filter(origin__**distance_lte=(user.profile.**geo_location,
> D(m=F('range'
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/measure.py", line 165, in __init__
> self.m, self._default_unit = self.default_units(kwargs)
>  File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/measure.py", line 49, in
> default_units
> if not isinstance(value, float): value = float(value)
>  TypeError: float() argument must be a string or a number
> I think the problem is that the D() isn't ran lazily - I can understand
> that. So I tried to just take the raw value from the range field (integer)
> which I supposed to work, but:
>
> >>> Order.objects.filter(origin__**distance_lte=(user.profile.**geo_location,
> F('range')))
> Traceback (most recent call last):
> File "", line 1, in 
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/query.py", line 69, in __repr__
> data = list(self[:REPR_OUTPUT_SIZE + 1])
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/query.py", line 84, in __len__
> self._result_cache.extend(**self._iter)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/query.py", line 273, in iterator
> for row in compiler.results_iter():
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/compiler.py", line 680, in
> results_iter
> for rows in self.execute_sql(MULTI):
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/compiler.py", line 725, in
> execute_sql
> sql, params = self.as_sql()
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/compiler.py", line 68, in as_sql
> where, w_params = self.query.where.as_sql(qn=qn,
> connection=self.connection)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/where.py", line 92, in as_sql
> sql, params = child.as_sql(qn=qn, connection=connection)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/db/**models/sql/where.py", line 95, in as_sql
> sql, params = self.make_atom(child, qn, connection)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/db/models/sql/**where.py", line 47,
> in make_atom
> spatial_sql = connection.ops.spatial_lookup_**sql(data, lookup_type,
> params_or_value, lvalue.field, qn)
> File "/Users/danger/devel/.**virtualenvs/proj/lib/python2.**
> 7/site-packages/django/**contrib/gis/db/backends/**postgis/operations.py",
> line 531, in spatial_lookup_sql
> raise ValueError('Argument type should be %s, got %s instead.' %
> (arg_type, type(value[1])))
> ValueError: Argument type should be (,  'django.contrib.gis.measure.**Distance'>, , ,
> ), got  instead.
>
> So how can I accomplish what I am trying to? Any help is appreciated!
>
> PS: I have posted this also to StackOverflow at
> http://stackoverflow.com/q/**9547069/755532?sem=2
>
> Thanks in advance!
>
> --
> Kind regards
>  Daniel
>
> --
> 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+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> 

Re: Django REST

2012-03-04 Thread Jani Tiainen
I've been very happy with django-rest-framework.

I think there exists at least django-piston to do the same.

And you can write it also "manually". Since REST is just architectural
specification and doesn't involve any special magic.

On Sun, Mar 4, 2012 at 8:13 PM, Bharath Mundlapudi wrote:

> Dear Django Users and Authors,
>
> I am wondering if there are any best practices or better way to write REST
> based apps on top of Django. I was using version 1.1 and not followed
> recent advancements. Can you kindly point me to links or references from
> your experience.
>
> Preferably out-of-the-box solutions.
>
> -Bharath
>
> --
> 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.
>

--

Jani Tiainen

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

2012-03-04 Thread Bharath Mundlapudi
Dear Django Users and Authors,

I am wondering if there are any best practices or better way to write REST
based apps on top of Django. I was using version 1.1 and not followed
recent advancements. Can you kindly point me to links or references from
your experience.

Preferably out-of-the-box solutions.

-Bharath

-- 
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-cms plugins - ImportError no module named: cmsplugin_filer_file....

2012-03-04 Thread doniyor
hey Amao, great help :))) i really didnot see this dummy mistake..
thanks great and chrs

On 4 Mrz., 15:53, Amao Zhao  wrote:
> the APP_INSTALLS in your settings.py is a list. please recheck your 'filer'
> and so no.
> 在 2012-3-4 下午10:07,"doniyor" 写道:
>
>
>
>
>
>
>
> > Hi there,
>
> > i need your help, i am trying to setup cms of my webpage, but
> > everytime i run the "python manage.py syncdb" the error comes:
> > django.core.exceptions.ImproperlyConfigured: ImportError filer
> > cmsplugin_filer_image : no module named filer
> > cmsplugin_filer_image
>
> > i have installed all possible django-cms plugins, i have django 1.3.1
> > running and python 2.7.
>
> > why is this error, as a result i dont have a available plugins in
> > cmspage to select.
>
> > please help me, is it a django version problem ?
>
> > this is my settings.py:
>
> >http://pastebin.com/K0VaK62K
>
> > thanks alot..
>
> > --
> > 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.



Re: How to use post_save signal ?

2012-03-04 Thread Nikhil Verma
Hi akaariai

I solved my problem by using snippet 1633 FileField/ImageField. Thanks for
making my concept in signals.


On Sun, Mar 4, 2012 at 7:23 PM, akaariai  wrote:

> On Sunday, March 4, 2012 3:12:20 PM UTC+2, Nikhil Verma wrote:
>>
>> Hi akaariai
>>
>> As you said i will remove the file and leave the file in file
>> system(mistake for writing delete).
>> Now what i have done is :-
>>
>> image: Currently: 
>> images/testimonial-bottom_2.**png
>> Change: Delete this file
>>
>> When you click the link Delete this file what it will do is it will
>> remove the path 
>> "images/testimonial-bottom_2.**png".But
>>  the problem begins when you press save button and open the same row
>> in django - admin it appears again as if it was not removed and actually it
>> is not removed from that ImageField . i have checked by going through shell.
>>
>> Actually i want implement ImageField of Django1.4b . It  has a
>> checkbox(remove_image) along with the ImageField asking for clear image and
>> when you click on that the image get  removed. How can i get the same thing
>> working for Django1.2.5 which i am using.
>>
>>
> One way is to check the source code of 1.4b and see what it does.
>
>
>> So i thought to make a checkbox ,click on that it will trigger a
>> post_save signal which first looks if the checkbox of remove_image is
>> checked and when save  button is pressed it wil remove the path of image.
>>
>> How can i implement that ? Thanks for help in advance .
>>
>>
> I have a bit hard time following what is the exact thing you want. So, the
> best advice I can give you is this: don't use the post_save signal. Use
> pre_save signal or better yet, a custom ModelForm. You must do the clearing
> of the image field _before_ the data gets saved into the database, and you
> can't do that from post_save signal.
>
>  - Anssi
>
> --
> 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/-/ORkjtr8LBHoJ.
>
> 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.
>



-- 
Regards
Nikhil Verma
+91-958-273-3156

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



How can I make a view called "push" to add +1 to my Entry.push model?

2012-03-04 Thread leaks
I have this in mind:

having entries in a page and people will be able to push them (voting them 
+1 to get them higher in the page).
The more pushes the higher the post will be displayed. (I order them by the 
amount of pushes)
I have put a submit button next to each post.

The question:

1.How can I make a view called "push" to add +1 to my Entry.push model?
2. Is it possible to make it for each user to vote once?

I have searched and i haven't really understood how request.POST and GET 
works...

Thanks in advance!!

-- 
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/-/KVp0D9ZalUMJ.
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-cms plugins - ImportError no module named: cmsplugin_filer_file....

2012-03-04 Thread Amao Zhao
the APP_INSTALLS in your settings.py is a list. please recheck your 'filer'
and so no.
在 2012-3-4 下午10:07,"doniyor" 写道:

> Hi there,
>
> i need your help, i am trying to setup cms of my webpage, but
> everytime i run the "python manage.py syncdb" the error comes:
> django.core.exceptions.ImproperlyConfigured: ImportError filer
> cmsplugin_filer_image : no module named filer
> cmsplugin_filer_image
>
>
> i have installed all possible django-cms plugins, i have django 1.3.1
> running and python 2.7.
>
> why is this error, as a result i dont have a available plugins in
> cmspage to select.
>
> please help me, is it a django version problem ?
>
> this is my settings.py:
>
> http://pastebin.com/K0VaK62K
>
> thanks alot..
>
> --
> 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.



Re: Django-cms plugins - ImportError no module named: cmsplugin_filer_file....

2012-03-04 Thread doniyor
by the way, i am using django-cms-2.2

On 4 Mrz., 15:07, doniyor  wrote:
> Hi there,
>
> i need your help, i am trying to setup cms of my webpage, but
> everytime i run the "python manage.py syncdb" the error comes:
> django.core.exceptions.ImproperlyConfigured: ImportError filer
> cmsplugin_filer_image : no module named filer
> cmsplugin_filer_image
>
> i have installed all possible django-cms plugins, i have django 1.3.1
> running and python 2.7.
>
> why is this error, as a result i dont have a available plugins in
> cmspage to select.
>
> please help me, is it a django version problem ?
>
> this is my settings.py:
>
> http://pastebin.com/K0VaK62K
>
> thanks alot..

-- 
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-cms plugins - ImportError no module named: cmsplugin_filer_file....

2012-03-04 Thread doniyor
Hi there,

i need your help, i am trying to setup cms of my webpage, but
everytime i run the "python manage.py syncdb" the error comes:
django.core.exceptions.ImproperlyConfigured: ImportError filer
cmsplugin_filer_image : no module named filer
cmsplugin_filer_image


i have installed all possible django-cms plugins, i have django 1.3.1
running and python 2.7.

why is this error, as a result i dont have a available plugins in
cmspage to select.

please help me, is it a django version problem ?

this is my settings.py:

http://pastebin.com/K0VaK62K

thanks alot..

-- 
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 to use post_save signal ?

2012-03-04 Thread akaariai
On Sunday, March 4, 2012 3:12:20 PM UTC+2, Nikhil Verma wrote:
>
> Hi akaariai
>
> As you said i will remove the file and leave the file in file 
> system(mistake for writing delete). 
> Now what i have done is :-
>
> image: Currently: 
> images/testimonial-bottom_2.png
>  
> Change: Delete this file
>
> When you click the link Delete this file what it will do is it will remove 
> the path 
> "images/testimonial-bottom_2.png".But
>  the problem begins when you press save button and open the same row 
> in django - admin it appears again as if it was not removed and actually it 
> is not removed from that ImageField . i have checked by going through shell.
>
> Actually i want implement ImageField of Django1.4b . It  has a 
> checkbox(remove_image) along with the ImageField asking for clear image and 
> when you click on that the image get  removed. How can i get the same thing 
> working for Django1.2.5 which i am using.
>
>
One way is to check the source code of 1.4b and see what it does.
 

> So i thought to make a checkbox ,click on that it will trigger a post_save 
> signal which first looks if the checkbox of remove_image is checked and 
> when save  button is pressed it wil remove the path of image.
>
> How can i implement that ? Thanks for help in advance .
>
>
I have a bit hard time following what is the exact thing you want. So, the 
best advice I can give you is this: don't use the post_save signal. Use 
pre_save signal or better yet, a custom ModelForm. You must do the clearing 
of the image field _before_ the data gets saved into the database, and you 
can't do that from post_save signal.

 - Anssi 

-- 
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/-/ORkjtr8LBHoJ.
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 to use post_save signal ?

2012-03-04 Thread Nikhil Verma
Hi akaariai

As you said i will remove the file and leave the file in file
system(mistake for writing delete).
Now what i have done is :-

image: Currently:
images/testimonial-bottom_2.png
Change: Delete this file

When you click the link Delete this file what it will do is it will remove
the path 
"images/testimonial-bottom_2.png".But
the problem begins when you press save button and open the same row
in django - admin it appears again as if it was not removed and actually it
is not removed from that ImageField . i have checked by going through shell.

Actually i want implement ImageField of Django1.4b . It  has a
checkbox(remove_image) along with the ImageField asking for clear image and
when you click on that the image get  removed. How can i get the same thing
working for Django1.2.5 which i am using.

So i thought to make a checkbox ,click on that it will trigger a post_save
signal which first looks if the checkbox of remove_image is checked and
when save  button is pressed it wil remove the path of image.

How can i implement that ? Thanks for help in advance .



On Sun, Mar 4, 2012 at 6:22 PM, akaariai  wrote:

>
> On Sunday, March 4, 2012 12:31:50 PM UTC+2, Nikhil Verma wrote:
>>
>> Hi all
>>
>> I am using Django-1.2.5 and i want to use post_save signal in the
>> following problem/task.
>>
>> I have :-
>> models.py
>>
>> image = models.ImageField(.)
>> remove_image = models.BooleanField()
>>
>> Now i want  :-
>>
>> 1) When the user uploads the file , the file path appears on the
>> imageField like this.
>>
>> Currently: 
>> images/testimonial-bottom_1.**png
>>
>> Change:
>>
>> I want to give the option to delete the file .So i made a field called
>> remove image which is a checkbox . Now when the user clicks that
>> remove_image checkbox and press save the image should get deleted. I was
>> going through the documentation and believe that this problem could be
>> solved by using post_save signal
>>
>>
>> I have not used signals so need help ,
>>
>>
>> def delete_old_image(sender, instance, using=None,*args, **kwargs):
>> try:
>> old_record = sender.objects.get(pk=instance**.pk
>> )
>> old_record.delete()
>> except sender.DoesNotExist:
>> pass
>> signals.post_save.connect(**delete_old_image, sender=Trip)
>>
>> How can i achieve this task by using signals or without signals.
>>
>> Any help will be appreciated.
>>
>> You have a misunderstanding in your code: when you fetch the old_record
> from sender.objects you are actually refetching the instance being saved.
> Then you do on to delete the instance. Is this really what you want?
>
> Now, if you want to delete the file in a signal, you should use pre_save
> signal, where you delete the image using instance.image.delete(save=False)
> or better jet set instance.image = None (see later for details). You should
> probably also clear the "save" flag, as otherwise that gets saved into the
> DB.
>
> Still, it is much better to handle the clearing of the image field by
> using a custom form, and then do the clearing of the image in some hook of
> the form or in the view directly (for ModelForm that would be overridden
> .save()). The checkbox remove_image isn't really part of your data model,
> so it should not be a field in you model class, just a user input element.
>
> Last, for some technicalities about file handling in transactional
> setting: To do file handling properly when using transactional databases
> you should actually do the file delete post-commit. The reason is this
> sequence of events:
>   - delete file
>   - do save
>   - for some reason the transaction is rolled back. (network error,
> integrity error in DB, electricity lost and so on).
>
> Now you have a model in the DB whose file field points to the now deleted
> file. The delete can't be rolled back.
>
> So, to be technically correct, you should do the .delete() in post-commit
> hook. Now the worst case is that the transaction gets committed, but for
> some reason the file can't be deleted (crash of the server at the wrong
> moment). But, this results just in a leftover file in the storage. That is
> easy to clean up and in most cases doesn't matter at all.
>
> As said, this is just a technicality. Django doesn't even provide that
> post-commit hook. I think I am going to suggest a pre/post commit signal,
> that could have other uses, too... However: there is a lesson here: are you
> sure you want to actually delete the actual file? You could just remove the
> link from the instance to that file, but leave the file in the file system.
>
>  - Anssi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> 

Re: How to use post_save signal ?

2012-03-04 Thread akaariai

On Sunday, March 4, 2012 12:31:50 PM UTC+2, Nikhil Verma wrote:
>
> Hi all 
>
> I am using Django-1.2.5 and i want to use post_save signal in the 
> following problem/task.
>
> I have :- 
> models.py
>
> image = models.ImageField(.)
> remove_image = models.BooleanField()
>
> Now i want  :-
>
> 1) When the user uploads the file , the file path appears on the 
> imageField like this.
>
> Currently: 
> images/testimonial-bottom_1.png
>  
>
> Change: 
>
> I want to give the option to delete the file .So i made a field called 
> remove image which is a checkbox . Now when the user clicks that 
> remove_image checkbox and press save the image should get deleted. I was 
> going through the documentation and believe that this problem could be 
> solved by using post_save signal
>
>
> I have not used signals so need help , 
>
>
> def delete_old_image(sender, instance, using=None,*args, **kwargs):
> try:
> old_record = sender.objects.get(pk=instance.pk)
> old_record.delete()
> except sender.DoesNotExist:
> pass
> signals.post_save.connect(delete_old_image, sender=Trip)
>
> How can i achieve this task by using signals or without signals.
>
> Any help will be appreciated.
>
> You have a misunderstanding in your code: when you fetch the old_record 
from sender.objects you are actually refetching the instance being saved. 
Then you do on to delete the instance. Is this really what you want?

Now, if you want to delete the file in a signal, you should use pre_save 
signal, where you delete the image using instance.image.delete(save=False) 
or better jet set instance.image = None (see later for details). You should 
probably also clear the "save" flag, as otherwise that gets saved into the 
DB.

Still, it is much better to handle the clearing of the image field by using 
a custom form, and then do the clearing of the image in some hook of the 
form or in the view directly (for ModelForm that would be overridden 
.save()). The checkbox remove_image isn't really part of your data model, 
so it should not be a field in you model class, just a user input element.

Last, for some technicalities about file handling in transactional setting: 
To do file handling properly when using transactional databases you should 
actually do the file delete post-commit. The reason is this sequence of 
events:
  - delete file
  - do save
  - for some reason the transaction is rolled back. (network error, 
integrity error in DB, electricity lost and so on).

Now you have a model in the DB whose file field points to the now deleted 
file. The delete can't be rolled back.

So, to be technically correct, you should do the .delete() in post-commit 
hook. Now the worst case is that the transaction gets committed, but for 
some reason the file can't be deleted (crash of the server at the wrong 
moment). But, this results just in a leftover file in the storage. That is 
easy to clean up and in most cases doesn't matter at all.

As said, this is just a technicality. Django doesn't even provide that 
post-commit hook. I think I am going to suggest a pre/post commit signal, 
that could have other uses, too... However: there is a lesson here: are you 
sure you want to actually delete the actual file? You could just remove the 
link from the instance to that file, but leave the file in the file system.

 - Anssi

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



How to use post_save signal ?

2012-03-04 Thread Nikhil Verma
Hi all

I am using Django-1.2.5 and i want to use post_save signal in the following
problem/task.

I have :-
models.py

image = models.ImageField(.)
remove_image = models.BooleanField()

Now i want  :-

1) When the user uploads the file , the file path appears on the imageField
like this.

Currently: 
images/testimonial-bottom_1.png

Change:

I want to give the option to delete the file .So i made a field called
remove image which is a checkbox . Now when the user clicks that
remove_image checkbox and press save the image should get deleted. I was
going through the documentation and believe that this problem could be
solved by using post_save signal


I have not used signals so need help ,


def delete_old_image(sender, instance, using=None,*args, **kwargs):
try:
old_record = sender.objects.get(pk=instance.pk)
old_record.delete()
except sender.DoesNotExist:
pass
signals.post_save.connect(delete_old_image, sender=Trip)

How can i achieve this task by using signals or without signals.

Any help will be appreciated.


-- 
Regards
Nikhil Verma
+91-958-273-3156

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