Re: ProgrammingError: relation "django_content_type" already exists

2015-03-24 Thread Mike Dewhirst
Still not getting very far. The error below* keeps turning up. Further 
to this, I ran migrate with --list and --settings=ssds.settings.dev and 
it returns ...


admin
 [ ] 0001_initial
auth
 [ ] 0001_initial
 [ ] 0002_alter_permission_name_max_length
 [ ] 0003_alter_user_email_max_length
 [ ] 0004_alter_user_username_opts
 [ ] 0005_alter_user_last_login_null
 [ ] 0006_require_contenttypes_0002
contenttypes
 [ ] 0001_initial
 [ ] 0002_remove_content_type_name
sessions
 [ ] 0001_initial
sites
 [ ] 0001_initial

The 1.7 docs say ...

The --list option will list all of the apps Django knows about, the 
migrations available for each app and if they are applied or not (marked 
by an [X] next to the migration name).


Apps without migrations are also included in the list, but will have (no 
migrations) printed under them.


None of my five apps are listed.

Running makemigrations returns "No changes detected" so I suppose the 
Django ones were done when I first ran manage.py migrate. That's only a 
guess.


I'll keep reading the docs.

Thanks in advance

Mike

* see below

On 24/03/2015 5:00 PM, Mike Dewhirst wrote:

This is my first stab at upgrading directly from Django 1.6.11 to 1.81c
to see what needs to be done. I thought I'd skip 1.7.x - is that a bad
idea? Is there some step in 1.7.x which eases the path to 1.8.x?

On first starting the project up using runserver on localhost it advises:

Python:   3.4
Django:   1.8c1
Database: ssds.climate.com.au
Postgres: 9.1
16:18:54

Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they
are applied.
Run 'python manage.py migrate' to apply them.

See below. Not sure where to go from here. Any ideas?

Thanks

Mike

On running manage.py migrate it returns a ProgrammingError as follows:

(xxex3) C:\Users\mike\env\xxex3\ssds>python manage.py migrate
Operations to perform:
   Synchronize unmigrated apps: admindocs, messages, credit, refer,
company, workplace, staticfiles, substance, common
   Apply all migrations: contenttypes, sessions, auth, sites, admin
Synchronizing apps without migrations:
   Creating tables...
 Running deferred SQL...
   Installing custom SQL...
Running migrations:
   Rendering model states... DONE
   Applying contenttypes.0001_initial...Traceback (most recent call last):
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py",
line 62, in execute
 return self.cursor.execute(sql)
psycopg2.ProgrammingError: relation "django_content_type" already exists


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
   File "manage.py", line 24, in 
 execute_from_command_line(sys.argv)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\__init__.py",

line 338, in execute_from_command_line
 utility.execute()
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\__init__.py",

line 330, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\base.py",
line 390, in run_from_argv
 self.execute(*args, **cmd_options)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\base.py",
line 441, in execute
 output = self.handle(*args, **options)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\core\management\commands\migrate.py",

line 221, in handle
 executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\executor.py",

line 94, in migrate
 self.apply_migration(states[migration], migration, fake=fake,
fake_initial=fake_initial)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\executor.py",

line 131, in apply_migration
 state = migration.apply(state, schema_editor)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\migration.py",

line 111, in apply
 operation.database_forwards(self.app_label, schema_editor,
old_state, project_state)

   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\migrations\operations\models.py",

line 59, in database_forwards
 schema_editor.create_model(model)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\base\schema.py",

line 282, in create_model
 self.execute(sql, params or None)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\base\schema.py",

line 107, in execute
 cursor.execute(sql, params)
   File
"C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py",
line 64, in execute
 return self.cursor.execute(sql, params)
   File "C:\Users\mike\env\xxex3\lib\site-packages\django\db\utils.py",
line 97, in __exit__
 six.reraise(dj_exc_type, dj_exc_value, traceback)
   File "C:\Users\mike\env\xxex3\lib\site-packages\django\utils\six.py",
line 658, in reraise
 raise

image handling

2015-03-24 Thread akash . patni
hi..
Can anyone please tell me how to handle old image after uploading new image.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/83341a1f-5684-4aad-8f87-268f25f15adb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread Andreas Kuhne
Hi,

I think you'll have to be more specific, what do you want to do with the
old image? Delete it? Use it again?

Regards,

Andréas

2015-03-24 10:08 GMT+01:00 :

> hi..
> Can anyone please tell me how to handle old image after uploading new
> image.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/83341a1f-5684-4aad-8f87-268f25f15adb%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALXYUb%3DOLdnWduQZeOGerZyZCSKV11%3Dq76chr1zOczYr7uJkgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
Hi ,
I want to delete the old image.

On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com 
wrote:
>
> hi..
> Can anyone please tell me how to handle old image after uploading new 
> image.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4aa4ac92-e622-4130-8ea0-dfbe46862c08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
This is my model
class User(models.Model):
first_name=models.CharField(verbose_name = "First Name 
*",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name 
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email 
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password 
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No 
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House 
No",max_length=10,blank=True)
address1=models.CharField(verbose_name = 
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name = 
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name = 
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name = 
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb) 
*",blank=True,upload_to='media/')

def __unicode__(self):
return self.first_name


this is my form
class Registration(forms.ModelForm):
  password = forms.CharField(label='Password 
*',widget=forms.PasswordInput())
  image = forms.ImageField(label='Select a file *',help_text='max. 1 
megabytes')
  class Meta:

view.py
def registration(request):
#request.session.set_test_cookie()
if request.method == "POST":
regform=Registration(request.POST,request.FILES)
if regform.is_valid():
   #item=resize_and_crop(img_path, modified_path, size, 
crop_type='top')
   regform.save();
   return HttpResponseRedirect('/login/')

else:
return 
render_to_response('registration.html',{"form":regform})
else:
regform=Registration()
return render_to_response('registration.html',{"form":regform})


can anyone please tell how to handle this means how to delete the old image

Please...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8cf2d1a-ce01-431e-9e86-cac5d8103cd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Image resizing

2015-03-24 Thread akash . patni
Hi..
can anyone please tell me how to resize the uploaded image
This is my model
class User(models.Model):
first_name=models.CharField(
verbose_name = "First Name *",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name 
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email 
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password 
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No 
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House 
No",max_length=10,blank=True)
address1=models.CharField(verbose_name = 
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name = 
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name = 
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name = 
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb) 
*",blank=True,upload_to='media/')

def __unicode__(self):
return self.first_name


this is my form
class Registration(forms.ModelForm):
  password = forms.CharField(label='Password 
*',widget=forms.PasswordInput())
  image = forms.ImageField(label='Select a file *',help_text='max. 1 
megabytes')
  class Meta:

view.py
def registration(request):
#request.session.set_test_cookie()
if request.method == "POST":
regform=Registration(request.POST,request.FILES)
if regform.is_valid():
   #item=resize_and_crop(img_path, modified_path, size, 
crop_type='top')
   regform.save();
   return HttpResponseRedirect('/login/')

else:
return 
render_to_response('registration.html',{"form":regform})
else:
regform=Registration()
return render_to_response('registration.html',{"form":regform})


def show_profile(request):
if 'username' in request.session:
 obj_user=User.objects.all().order_by('-id')
 return 
render_to_response("index.html",{"obj_user":obj_user,"message":"Hello 
World"})
else:
return HttpResponseRedirect('/login/')

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
This is my edit profile function in view

def edit_profile(request):  
if 'username' in request.session:
user_id=request.POST.get('id')
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
if request.method=="POST":
regform=Registration(instance=usr_obj,data = request.POST)
if regform.is_valid():
regform.save();
return HttpResponseRedirect('/index/')
else:
return 
render_to_response("edit_profile.html",{"form":regform,})
else:   
user_id=request.GET.get('id')
usr_obj=User.objects.get(id=int(user_id))
 
#temp_data={'first_name':user_id.first_name,'last_name':user_id.last_name,'email':user_id.email,'password':user_id.password,'dob':user_id.dob,'mobileno':user_id.mobileno,'houseno':user_id.houseno,'address1':user_id.address1,'city':user_id.city,'state':user_id.state,'pincode':user_id.pincode,'country':user_id.country,'comment':user_id.comment,'sex':user_id.sex}
regform=Registration(instance=usr_obj)
return 
render_to_response("edit_profile.html",{"form":regform,"user_id":user_id})


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc65c1d1-62dd-4cfe-b957-ec4b5b1278e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
hi
any answer

On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com 
wrote:
>
> hi..
> Can anyone please tell me how to handle old image after uploading new 
> image.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3dbbee2-ebcb-4900-b833-d146ecebdbd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re-run only tests that failed last time

2015-03-24 Thread Gergely Polonkai
Hello,

I have a pretty extended test suite for my application, which can run for
about 15 minutes. Now when I introduce an error, I will be notified of it
pretty late, and a one-liner fix needs another 15 minutes to check. Of
course if only one of my tests fail, I can add the name of the test case as
a parameter to manage.py test, but in case of many failures it’s pretty
hard to do the same.

Is there a way to run only the tests that failed last time, even if I have
to install a separate app/module for that? A quick Google search gave me no
usable results.

Best,
Gergely

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBU%2B-SR3uASD_eQc_c%2BKFp%3DvCgaWga6pfUgA%2BJHr5HgkCHQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread aRkadeFR

When do you want to delete the old image?

On 03/24/2015 10:59 AM, akash.pa...@ranosys.com wrote:

Hi ,
I want to delete the old image.

On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, 
akash...@ranosys.com wrote:


hi..
Can anyone please tell me how to handle old image after uploading
new image.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4aa4ac92-e622-4130-8ea0-dfbe46862c08%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55113CF7.6060604%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread akash . patni
When i edit image that is when i upload new image,the old image should get 
deleted

On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com 
wrote:
>
> hi..
> Can anyone please tell me how to handle old image after uploading new 
> image.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread Andreas Kuhne
Hi,

Ok, so what you should do is add a signal to pre save and then delete the
old image if the new image is attached.

Something like this should work:

from django.core.files.storage import default_storage as storage
from django.db.models.signals import pre_save


def image_delete(sender, instance, *args, **kwargs):
  if instance.pk:
old_instance = User.objects.get(pk=instance.pk)

if old_instance.image != instance.image and instance.image:
  storage.delete(old_instance.image.name)

pre_save.connect(image_delete, sender=User)

You can see more information about signals here:
https://docs.djangoproject.com/en/1.7/topics/signals/

Regards,

Andréas

2015-03-24 11:40 GMT+01:00 :

> When i edit image that is when i upload new image,the old image should get
> deleted
>
> On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com
> wrote:
>>
>> hi..
>> Can anyone please tell me how to handle old image after uploading new
>> image.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Image resizing

2015-03-24 Thread Andreas Kuhne
Hi,

Check out the easy_thumbnails plugin.
http://easy-thumbnails.readthedocs.org/en/2.1/

It automatically resizes all images to the size you want if you use it
correctly.

Regards,

Andréas

2015-03-24 11:07 GMT+01:00 :

> Hi..
> can anyone please tell me how to resize the uploaded image
> This is my model
> class User(models.Model):
> first_name=models.CharField(
> verbose_name = "First Name *",max_length=20,blank=False)
> last_name=models.CharField(verbose_name = "Last Name
> *",max_length=20,blank=False)
> username=models.EmailField(verbose_name = "Email
> *",max_length=30,blank=False)
> password=models.CharField(verbose_name = "Password
> *",max_length=15,blank=False)
> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
> mobileno=models.CharField(verbose_name = "Mobile No
> *",max_length=20,blank=False)
> houseno=models.CharField(verbose_name = "House
> No",max_length=10,blank=True)
> address1=models.CharField(verbose_name =
> "Adress1",max_length=30,blank=True)
> city=models.CharField(verbose_name = "City",max_length=20,blank=True)
> state=models.CharField(verbose_name = "State",max_length=30,blank=
> True)
> pincode=models.CharField(verbose_name = "Pincode",max_length=20,blank=
> True)
> country=models.CharField(verbose_name = "Country",max_length=30,blank=
> True)
> comment=models.CharField(verbose_name = "Comment",max_length=200,
> blank=True)
> sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
> image=models.FileField(verbose_name = "Image(limit 1Mb)
> *",blank=True,upload_to='media/')
>
> def __unicode__(self):
> return self.first_name
>
>
> this is my form
> class Registration(forms.ModelForm):
>   password = forms.CharField(label='Password
> *',widget=forms.PasswordInput())
>   image = forms.ImageField(label='Select a file *',help_text='max. 1
> megabytes')
>   class Meta:
>
> view.py
> def registration(request):
> #request.session.set_test_cookie()
> if request.method == "POST":
> regform=Registration(request.POST,request.FILES)
> if regform.is_valid():
>#item=resize_and_crop(img_path, modified_path, size,
> crop_type='top')
>regform.save();
>return HttpResponseRedirect('/login/')
>
> else:
> return render_to_response('registration.html',{"form":
> regform})
> else:
> regform=Registration()
> return render_to_response('registration.html',{"form":regform})
>
>
> def show_profile(request):
> if 'username' in request.session:
>  obj_user=User.objects.all().order_by('-id')
>  return
> render_to_response("index.html",{"obj_user":obj_user,"message":"Hello
> World"})
> else:
> return HttpResponseRedirect('/login/')
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALXYUb%3DJWPh_5Fgk8YiGTsacVLab6xakpEMW2z2GK7xd71PUpA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Re-run only tests that failed last time

2015-03-24 Thread Andreas Kuhne
If you have created packages for your tests, you can run all tests in a
package. If the tests aren't in the same package, it won't help you however.

Regards,

Andréas

2015-03-24 11:27 GMT+01:00 Gergely Polonkai :

> Hello,
>
> I have a pretty extended test suite for my application, which can run for
> about 15 minutes. Now when I introduce an error, I will be notified of it
> pretty late, and a one-liner fix needs another 15 minutes to check. Of
> course if only one of my tests fail, I can add the name of the test case as
> a parameter to manage.py test, but in case of many failures it’s pretty
> hard to do the same.
>
> Is there a way to run only the tests that failed last time, even if I have
> to install a separate app/module for that? A quick Google search gave me no
> usable results.
>
> Best,
> Gergely
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACczBU%2B-SR3uASD_eQc_c%2BKFp%3DvCgaWga6pfUgA%2BJHr5HgkCHQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALXYUbnx9KRCi%2BNSCbLsUp3Hym9V5DWcBSFuw%3D5-cK5HTwMyjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Image resizing

2015-03-24 Thread Akash Patni
can you please suggest me another answer...

On Tue, Mar 24, 2015 at 6:13 PM, Andreas Kuhne 
wrote:

> Hi,
>
> Check out the easy_thumbnails plugin.
> http://easy-thumbnails.readthedocs.org/en/2.1/
>
> It automatically resizes all images to the size you want if you use it
> correctly.
>
> Regards,
>
> Andréas
>
> 2015-03-24 11:07 GMT+01:00 :
>
>> Hi..
>> can anyone please tell me how to resize the uploaded image
>> This is my model
>> class User(models.Model):
>> first_name=models.CharField(
>> verbose_name = "First Name *",max_length=20,blank=False)
>> last_name=models.CharField(verbose_name = "Last Name
>> *",max_length=20,blank=False)
>> username=models.EmailField(verbose_name = "Email
>> *",max_length=30,blank=False)
>> password=models.CharField(verbose_name = "Password
>> *",max_length=15,blank=False)
>> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
>> mobileno=models.CharField(verbose_name = "Mobile No
>> *",max_length=20,blank=False)
>> houseno=models.CharField(verbose_name = "House
>> No",max_length=10,blank=True)
>> address1=models.CharField(verbose_name =
>> "Adress1",max_length=30,blank=True)
>> city=models.CharField(verbose_name = "City",max_length=20,blank=True)
>> state=models.CharField(verbose_name = "State",max_length=30,blank=
>> True)
>> pincode=models.CharField(verbose_name =
>> "Pincode",max_length=20,blank=True)
>> country=models.CharField(verbose_name =
>> "Country",max_length=30,blank=True)
>> comment=models.CharField(verbose_name = "Comment",max_length=200,
>> blank=True)
>> sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
>> image=models.FileField(verbose_name = "Image(limit 1Mb)
>> *",blank=True,upload_to='media/')
>>
>> def __unicode__(self):
>> return self.first_name
>>
>>
>> this is my form
>> class Registration(forms.ModelForm):
>>   password = forms.CharField(label='Password
>> *',widget=forms.PasswordInput())
>>   image = forms.ImageField(label='Select a file *',help_text='max. 1
>> megabytes')
>>   class Meta:
>>
>> view.py
>> def registration(request):
>> #request.session.set_test_cookie()
>> if request.method == "POST":
>> regform=Registration(request.POST,request.FILES)
>> if regform.is_valid():
>>#item=resize_and_crop(img_path, modified_path, size,
>> crop_type='top')
>>regform.save();
>>return HttpResponseRedirect('/login/')
>>
>> else:
>> return render_to_response('registration.html',{"form":
>> regform})
>> else:
>> regform=Registration()
>> return render_to_response('registration.html',{"form":regform})
>>
>>
>> def show_profile(request):
>> if 'username' in request.session:
>>  obj_user=User.objects.all().order_by('-id')
>>  return
>> render_to_response("index.html",{"obj_user":obj_user,"message":"Hello
>> World"})
>> else:
>> return HttpResponseRedirect('/login/')
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/XjuyFyKNnEI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUb%3DJWPh_5Fgk8YiGTsacVLab6xakpEMW2z2GK7xd71PUpA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Best Regards,*
Akash Patni
Software Engineer




*[image: ranosys]   [image: facebook]
[image: twitter]
[image: linkedin]
[image:
googleplus] 

Re: image handling

2015-03-24 Thread Akash Patni
Hey,
I am new to django. I have other feilds also other than image field in my
form, so will you please tell me how to use above mentioned function in
edit_profile function in view, Can i call another function from another
function in views.py, if yes please tell me

On Tue, Mar 24, 2015 at 6:11 PM, Andreas Kuhne 
wrote:

> Hi,
>
> Ok, so what you should do is add a signal to pre save and then delete the
> old image if the new image is attached.
>
> Something like this should work:
>
> from django.core.files.storage import default_storage as storage
> from django.db.models.signals import pre_save
>
>
> def image_delete(sender, instance, *args, **kwargs):
>   if instance.pk:
> old_instance = User.objects.get(pk=instance.pk)
>
> if old_instance.image != instance.image and instance.image:
>   storage.delete(old_instance.image.name)
>
> pre_save.connect(image_delete, sender=User)
>
> You can see more information about signals here:
> https://docs.djangoproject.com/en/1.7/topics/signals/
>
> Regards,
>
> Andréas
>
> 2015-03-24 11:40 GMT+01:00 :
>
>> When i edit image that is when i upload new image,the old image should
>> get deleted
>>
>> On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com
>> wrote:
>>>
>>> hi..
>>> Can anyone please tell me how to handle old image after uploading new
>>> image.
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/oZrAdWgzwo0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Best Regards,*
Akash Patni
Software Engineer




*[image: ranosys]   [image: facebook]
[image: twitter]
[image: linkedin]
[image:
googleplus]  Head Office: Oxley Bizhub,
#06-48 | 73 Ubi Road 1 | Singapore - 408733Tel: +65 66331556  |  HP: +65
98573420Global Offices:San Francisco, USA | Jaipur, India | Bikaner, India*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANSMZiTGE4rue_LtY3YrsERGqBuy%3DoFX0eJb_9o81R_us-OibQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Image resizing

2015-03-24 Thread Andreas Kuhne
You can use Pillow to change the size of the images yourself. That is
however pretty complicated and IMO not really worth the effort. I would go
with easy_thumbnails.

Regards,

Andréas

2015-03-24 14:04 GMT+01:00 Akash Patni :

> can you please suggest me another answer...
>
> On Tue, Mar 24, 2015 at 6:13 PM, Andreas Kuhne  > wrote:
>
>> Hi,
>>
>> Check out the easy_thumbnails plugin.
>> http://easy-thumbnails.readthedocs.org/en/2.1/
>>
>> It automatically resizes all images to the size you want if you use it
>> correctly.
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-03-24 11:07 GMT+01:00 :
>>
>>> Hi..
>>> can anyone please tell me how to resize the uploaded image
>>> This is my model
>>> class User(models.Model):
>>> first_name=models.CharField(
>>> verbose_name = "First Name *",max_length=20,blank=False)
>>> last_name=models.CharField(verbose_name = "Last Name
>>> *",max_length=20,blank=False)
>>> username=models.EmailField(verbose_name = "Email
>>> *",max_length=30,blank=False)
>>> password=models.CharField(verbose_name = "Password
>>> *",max_length=15,blank=False)
>>> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
>>> mobileno=models.CharField(verbose_name = "Mobile No
>>> *",max_length=20,blank=False)
>>> houseno=models.CharField(verbose_name = "House
>>> No",max_length=10,blank=True)
>>> address1=models.CharField(verbose_name =
>>> "Adress1",max_length=30,blank=True)
>>> city=models.CharField(verbose_name = "City",max_length=20,blank=
>>> True)
>>> state=models.CharField(verbose_name = "State",max_length=30,blank=
>>> True)
>>> pincode=models.CharField(verbose_name =
>>> "Pincode",max_length=20,blank=True)
>>> country=models.CharField(verbose_name =
>>> "Country",max_length=30,blank=True)
>>> comment=models.CharField(verbose_name = "Comment",max_length=200,
>>> blank=True)
>>> sex=models.CharField(verbose_name = "Sex
>>> *",max_length=5,blank=False)
>>> image=models.FileField(verbose_name = "Image(limit 1Mb)
>>> *",blank=True,upload_to='media/')
>>>
>>> def __unicode__(self):
>>> return self.first_name
>>>
>>>
>>> this is my form
>>> class Registration(forms.ModelForm):
>>>   password = forms.CharField(label='Password
>>> *',widget=forms.PasswordInput())
>>>   image = forms.ImageField(label='Select a file *',help_text='max. 1
>>> megabytes')
>>>   class Meta:
>>>
>>> view.py
>>> def registration(request):
>>> #request.session.set_test_cookie()
>>> if request.method == "POST":
>>> regform=Registration(request.POST,request.FILES)
>>> if regform.is_valid():
>>>#item=resize_and_crop(img_path, modified_path, size,
>>> crop_type='top')
>>>regform.save();
>>>return HttpResponseRedirect('/login/')
>>>
>>> else:
>>> return render_to_response('registration.html',{"form":
>>> regform})
>>> else:
>>> regform=Registration()
>>> return render_to_response('registration.html',{"form":regform})
>>>
>>>
>>> def show_profile(request):
>>> if 'username' in request.session:
>>>  obj_user=User.objects.all().order_by('-id')
>>>  return
>>> render_to_response("index.html",{"obj_user":obj_user,"message":"Hello
>>> World"})
>>> else:
>>> return HttpResponseRedirect('/login/')
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/5938a0d0-af8a-44aa-96c4-5d234f3e2cc4%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/XjuyFyKNnEI/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CALXYUb%3DJWPh_5Fgk8YiGTsacVLab6xakpEMW2z2GK7xd71PUpA%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://grou

Re: image handling

2015-03-24 Thread Andreas Kuhne
Hi,

You shouldn't do it in the view, do it in the database model instead. It
won't do anything to any other fields than the image field the way I wrote
the function (all other fields are untouched).

The reason you shouldn't do it in the view, is because if you were to
update the image any other place than via the view, the code wouldn't run.
It's more sensible and more DRY to do it in the model.

Regards,

Andréas

2015-03-24 14:10 GMT+01:00 Akash Patni :

> Hey,
> I am new to django. I have other feilds also other than image field in my
> form, so will you please tell me how to use above mentioned function in
> edit_profile function in view, Can i call another function from another
> function in views.py, if yes please tell me
>
> On Tue, Mar 24, 2015 at 6:11 PM, Andreas Kuhne  > wrote:
>
>> Hi,
>>
>> Ok, so what you should do is add a signal to pre save and then delete the
>> old image if the new image is attached.
>>
>> Something like this should work:
>>
>> from django.core.files.storage import default_storage as storage
>> from django.db.models.signals import pre_save
>>
>>
>> def image_delete(sender, instance, *args, **kwargs):
>>   if instance.pk:
>> old_instance = User.objects.get(pk=instance.pk)
>>
>> if old_instance.image != instance.image and instance.image:
>>   storage.delete(old_instance.image.name)
>>
>> pre_save.connect(image_delete, sender=User)
>>
>> You can see more information about signals here:
>> https://docs.djangoproject.com/en/1.7/topics/signals/
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-03-24 11:40 GMT+01:00 :
>>
>>> When i edit image that is when i upload new image,the old image should
>>> get deleted
>>>
>>> On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com
>>> wrote:

 hi..
 Can anyone please tell me how to handle old image after uploading new
 image.

>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/oZrAdWgzwo0/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Best Regards,*
> Akash Patni
> Software Engineer
>
>
>
>
> *[image: ranosys]   [image: facebook]
> [image: twitter]
> [image: linkedin]
> [image:
> googleplus]  Head Office: Oxley Bizhub,
> #06-48 | 73 Ubi Road 1 | Singapore - 408733Tel: +65 66331556  |  HP: +65
> 98573420Global Offices:San Francisco, USA | Jaipur, India | Bikaner, India*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANSMZiTGE4rue_LtY3YrsERGqBuy%3DoFX0eJb_9o81R_us-OibQ%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, sen

Re: image handling

2015-03-24 Thread Akash Patni
is there any other changes that i have to made in model like how this above
mentioned function will be call.

Please suggest

On Tue, Mar 24, 2015 at 6:43 PM, Andreas Kuhne 
wrote:

> Hi,
>
> You shouldn't do it in the view, do it in the database model instead. It
> won't do anything to any other fields than the image field the way I wrote
> the function (all other fields are untouched).
>
> The reason you shouldn't do it in the view, is because if you were to
> update the image any other place than via the view, the code wouldn't run.
> It's more sensible and more DRY to do it in the model.
>
> Regards,
>
> Andréas
>
> 2015-03-24 14:10 GMT+01:00 Akash Patni :
>
>> Hey,
>> I am new to django. I have other feilds also other than image field in my
>> form, so will you please tell me how to use above mentioned function in
>> edit_profile function in view, Can i call another function from another
>> function in views.py, if yes please tell me
>>
>> On Tue, Mar 24, 2015 at 6:11 PM, Andreas Kuhne <
>> andreas.ku...@suitopia.com> wrote:
>>
>>> Hi,
>>>
>>> Ok, so what you should do is add a signal to pre save and then delete
>>> the old image if the new image is attached.
>>>
>>> Something like this should work:
>>>
>>> from django.core.files.storage import default_storage as storage
>>> from django.db.models.signals import pre_save
>>>
>>>
>>> def image_delete(sender, instance, *args, **kwargs):
>>>   if instance.pk:
>>> old_instance = User.objects.get(pk=instance.pk)
>>>
>>> if old_instance.image != instance.image and instance.image:
>>>   storage.delete(old_instance.image.name)
>>>
>>> pre_save.connect(image_delete, sender=User)
>>>
>>> You can see more information about signals here:
>>> https://docs.djangoproject.com/en/1.7/topics/signals/
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>> 2015-03-24 11:40 GMT+01:00 :
>>>
 When i edit image that is when i upload new image,the old image should
 get deleted

 On Tuesday, March 24, 2015 at 2:40:35 PM UTC+5:30, akash...@ranosys.com
 wrote:
>
> hi..
> Can anyone please tell me how to handle old image after uploading new
> image.
>
  --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at http://groups.google.com/group/django-users.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/ca9fa002-cbd5-4bbf-b42c-2a6ce88e8e0c%40googlegroups.com
 
 .

 For more options, visit https://groups.google.com/d/optout.

>>>
>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/django-users/oZrAdWgzwo0/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CALXYUbkpM6op303LMxA2iGNuzqgzB%3DjBPWw2KXkpjwdaho2Z%2BQ%40mail.gmail.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> *Best Regards,*
>> Akash Patni
>> Software Engineer
>>
>>
>>
>>
>> *[image: ranosys]   [image: facebook]
>> [image: twitter]
>> [image: linkedin]
>> [image:
>> googleplus]  Head Office: Oxley Bizhub,
>> #06-48 | 73 Ubi Road 1 | Singapore - 408733Tel: +65 66331556  |  HP: +65
>> 98573420Global Offices:San Francisco, USA | Jaipur, India | Bikaner, India*
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CANSMZiTGE4rue_LtY3YrsERGqBuy%3DoFX0eJb_9o81R_us-OibQ%40mail.gmail.com
>> 

Re: image handling

2015-03-24 Thread Akash Patni
i had made the changes in model .py but its not working

here is model.py


from django.db import models
import django.forms as forms
from virtualenv import REQUIRED_FILES
from _mysql import NULL
from datetime import datetime, date, time, timedelta
import time
import calendar
from django.contrib.auth.models import User
import os
from uuid import uuid4
from django.core.files.storage import default_storage as storage
from django.db.models.signals import pre_save


def path_and_rename(path):
def wrapper(instance, filename):
ext = filename.split('.')[-1]
# get filename
if instance.pk:
filename = '{}.{}'.format(instance.pk, ext)
else:
# set filename as random string
filename = '{}.{}'.format(uuid4().hex, ext)
# return the whole path to the file
return os.path.join(path, filename)
return wrapper

def image_delete(sender, instance, *args, **kwargs):
  if instance.pk:
old_instance = User.objects.get(pk=instance.pk)

if old_instance.image != instance.image and instance.image:
  storage.delete(old_instance.image.name)

pre_save.connect(image_delete, sender=User)

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

def __unicode__(self):
return self.name

class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()

def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)

class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()

def __unicode__(self):
return self.title

class User(models.Model):
first_name=models.CharField(verbose_name = "First Name
*",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House
No",max_length=10,blank=True)
address1=models.CharField(verbose_name =
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name =
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name =
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name =
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb)
*",blank=True,upload_to=path_and_rename(''))

def __unicode__(self):
return self.first_name




On Tue, Mar 24, 2015 at 6:47 PM, Akash Patni 
wrote:

> is there any other changes that i have to made in model like how this
> above mentioned function will be call.
>
> Please suggest
>
> On Tue, Mar 24, 2015 at 6:43 PM, Andreas Kuhne  > wrote:
>
>> Hi,
>>
>> You shouldn't do it in the view, do it in the database model instead. It
>> won't do anything to any other fields than the image field the way I wrote
>> the function (all other fields are untouched).
>>
>> The reason you shouldn't do it in the view, is because if you were to
>> update the image any other place than via the view, the code wouldn't run.
>> It's more sensible and more DRY to do it in the model.
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-03-24 14:10 GMT+01:00 Akash Patni :
>>
>>> Hey,
>>> I am new to django. I have other feilds also other than image field in
>>> my form, so will you please tell me how to use above mentioned function in
>>> edit_profile function in view, Can i call another function from another
>>> function in views.py, if yes please tell me
>>>
>>> On Tue, Mar 24, 2015 at 6:11 PM, Andreas Kuhne <
>>> andreas.ku...@suitopia.com> wrote:
>>>
 Hi,

 Ok, so what you should do is add a signal to pre save and then delete
 the old image if the new image is attached.

 Something like this should work:

 from django.core.files.storage import default_storage as storage
 from django.db.models.signals import pre_save


 def image_delete(sender, instance, *args, **kwargs):
   if instance.pk:
 old_instance = User.objects.get(pk=instance.pk)

 if old_instance.image != instance.image a

Re: Re-run only tests that failed last time

2015-03-24 Thread Erik Cederstrand

> Den 24/03/2015 kl. 11.27 skrev Gergely Polonkai :
> 
> I have a pretty extended test suite for my application, which can run for 
> about 15 minutes. Now when I introduce an error, I will be notified of it 
> pretty late, and a one-liner fix needs another 15 minutes to check. Of course 
> if only one of my tests fail, I can add the name of the test case as a 
> parameter to manage.py test, but in case of many failures it’s pretty hard to 
> do the same.
> 
> Is there a way to run only the tests that failed last time, even if I have to 
> install a separate app/module for that? A quick Google search gave me no 
> usable results.

Only re-running failed tests partly defeats the purpose of testing. Your fix 
for failing test case A may introduce a failure in test case B.

Instead, I would look into either tweaking you very slow test so they run 
faster, or splitting up your test cases into fast and slow tests, so you can 
run your slow tests less frequently depending on some setting.

Erik

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4A592356-7DB3-44B5-8ACC-332B4811E40D%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Re-run only tests that failed last time

2015-03-24 Thread Ramiro Morales
On Tue, Mar 24, 2015 at 7:27 AM, Gergely Polonkai  wrote:
> Hello,
>
> I have a pretty extended test suite for my application, which can run for
> about 15 minutes. Now when I introduce an error, I will be notified of it
> pretty late, and a one-liner fix needs another 15 minutes to check. Of
> course if only one of my tests fail, I can add the name of the test case as
> a parameter to manage.py test, but in case of many failures it’s pretty hard
> to do the same.
>
> Is there a way to run only the tests that failed last time, even if I have
> to install a separate app/module for that? A quick Google search gave me no
> usable results.

Mine found:

https://pypi.python.org/pypi/django-juno-testrunner
http://nose.readthedocs.org/en/latest/plugins/testid.html#looping-over-failed-tests
plus https://github.com/django-nose/django-nose

-- 
Ramiro Morales
@ramiromorales

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO7PdF_-Km0%2BHC9jcJ%3DfvFJEJZqQoA_Xp_uSL6r0cTCSXjhN%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread Andreas Kuhne
First, make sure that the whitespace is the same in all of your methods (in
python whitespace is significant, which means that you should indent all
files the same amount, I wrote my example in my email, so I only indented
twice, you seem to have 4 blankspaces in your file, so make sure the
indentation is the same).

Secondly, I think that you should add the code I sent to the __init__.py
file in the project itself (in the same directory that you have you
models.py). That way it will be run during startup (which needs to be done).

Regards,

Andréas

2015-03-24 14:20 GMT+01:00 Akash Patni :

> i had made the changes in model .py but its not working
>
> here is model.py
>
>
> from django.db import models
> import django.forms as forms
> from virtualenv import REQUIRED_FILES
> from _mysql import NULL
> from datetime import datetime, date, time, timedelta
> import time
> import calendar
> from django.contrib.auth.models import User
> import os
> from uuid import uuid4
> from django.core.files.storage import default_storage as storage
> from django.db.models.signals import pre_save
>
>
> def path_and_rename(path):
> def wrapper(instance, filename):
> ext = filename.split('.')[-1]
> # get filename
> if instance.pk:
> filename = '{}.{}'.format(instance.pk, ext)
> else:
> # set filename as random string
> filename = '{}.{}'.format(uuid4().hex, ext)
> # return the whole path to the file
> return os.path.join(path, filename)
> return wrapper
>
> def image_delete(sender, instance, *args, **kwargs):
>   if instance.pk:
> old_instance = User.objects.get(pk=instance.pk)
>
> if old_instance.image != instance.image and instance.image:
>   storage.delete(old_instance.image.name)
>
> pre_save.connect(image_delete, sender=User)
>
> class Publisher(models.Model):
> name = models.CharField(max_length=30)
> address = models.CharField(max_length=50)
> city = models.CharField(max_length=60)
> state_province = models.CharField(max_length=30)
> country = models.CharField(max_length=50)
> website = models.URLField()
>
> def __unicode__(self):
> return self.name
>
> class Author(models.Model):
> first_name = models.CharField(max_length=30)
> last_name = models.CharField(max_length=40)
> email = models.EmailField()
>
> def __unicode__(self):
> return u'%s %s' % (self.first_name, self.last_name)
>
> class Book(models.Model):
> title = models.CharField(max_length=100)
> authors = models.ManyToManyField(Author)
> publisher = models.ForeignKey(Publisher)
> publication_date = models.DateField()
>
> def __unicode__(self):
> return self.title
>
> class User(models.Model):
> first_name=models.CharField(verbose_name = "First Name
> *",max_length=20,blank=False)
> last_name=models.CharField(verbose_name = "Last Name
> *",max_length=20,blank=False)
> username=models.EmailField(verbose_name = "Email
> *",max_length=30,blank=False)
> password=models.CharField(verbose_name = "Password
> *",max_length=15,blank=False)
> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
> mobileno=models.CharField(verbose_name = "Mobile No
> *",max_length=20,blank=False)
> houseno=models.CharField(verbose_name = "House
> No",max_length=10,blank=True)
> address1=models.CharField(verbose_name =
> "Adress1",max_length=30,blank=True)
> city=models.CharField(verbose_name = "City",max_length=20,blank=True)
> state=models.CharField(verbose_name = "State",max_length=30,blank=True)
> pincode=models.CharField(verbose_name =
> "Pincode",max_length=20,blank=True)
> country=models.CharField(verbose_name =
> "Country",max_length=30,blank=True)
> comment=models.CharField(verbose_name =
> "Comment",max_length=200,blank=True)
> sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
> image=models.FileField(verbose_name = "Image(limit 1Mb)
> *",blank=True,upload_to=path_and_rename(''))
>
> def __unicode__(self):
> return self.first_name
>
>
>
>
> On Tue, Mar 24, 2015 at 6:47 PM, Akash Patni 
> wrote:
>
>> is there any other changes that i have to made in model like how this
>> above mentioned function will be call.
>>
>> Please suggest
>>
>> On Tue, Mar 24, 2015 at 6:43 PM, Andreas Kuhne <
>> andreas.ku...@suitopia.com> wrote:
>>
>>> Hi,
>>>
>>> You shouldn't do it in the view, do it in the database model instead. It
>>> won't do anything to any other fields than the image field the way I wrote
>>> the function (all other fields are untouched).
>>>
>>> The reason you shouldn't do it in the view, is because if you were to
>>> update the image any other place than via the view, the code wouldn't run.
>>> It's more sensible and more DRY to do it in the model.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>> 2015-03-24 14:10 GMT+01:00 Akash Patni :
>>>
 Hey,
 I am new to django. I have other feilds

Re: Re-run only tests that failed last time

2015-03-24 Thread Gergely Polonkai
@Erik: On the CI side, certainly, I will run all the tests upon each
commit. I want to utilize this thing only on my developer machine, so I can
do a quick run after I think I fixed a problem. Naturally, if those failing
tests are green, I will run the whole suite again.

Separating/tweaking my current tests is not really an option; the whole
project is pretty big, with some large apps (yes, those must be cut in
smaller pieces, but that’s not today’s work yet). It will happen, though,
but thanks for pointing it out!

@Ramiro Morales: This juno test runner seems promising, thank you for the
link!

On 24 March 2015 at 15:08, Ramiro Morales  wrote:

> On Tue, Mar 24, 2015 at 7:27 AM, Gergely Polonkai 
> wrote:
> > Hello,
> >
> > I have a pretty extended test suite for my application, which can run for
> > about 15 minutes. Now when I introduce an error, I will be notified of it
> > pretty late, and a one-liner fix needs another 15 minutes to check. Of
> > course if only one of my tests fail, I can add the name of the test case
> as
> > a parameter to manage.py test, but in case of many failures it’s pretty
> hard
> > to do the same.
> >
> > Is there a way to run only the tests that failed last time, even if I
> have
> > to install a separate app/module for that? A quick Google search gave me
> no
> > usable results.
>
> Mine found:
>
> https://pypi.python.org/pypi/django-juno-testrunner
>
> http://nose.readthedocs.org/en/latest/plugins/testid.html#looping-over-failed-tests
> plus https://github.com/django-nose/django-nose
>
> --
> Ramiro Morales
> @ramiromorales
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAO7PdF_-Km0%2BHC9jcJ%3DfvFJEJZqQoA_Xp_uSL6r0cTCSXjhN%2Bg%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBU%2B3gm7COWJnJqCd80u12Upk%3DhFnfjpZGF7D1MnJfMb9WQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Why is list(Model.objects.all()) 10x slower against an Oracle database as compared to Postgres?

2015-03-24 Thread Daniel Porter
I have an application that we run locally against a postgres database but 
our dev/test/prod servers all run Oracle.

The command list(Person.objects.all()) runs remarkably faster against my 
local Postgresql database. It takes at least 10x longer against an Oracle 
database. The thing is the query itself doesn't seem to be holding it up. 

I don't really know how to track this down without going and putting random 
print datetimes in the django sourcecode. I'm using django 1.4, and the 
cx_oracle driver to communicate with oracle.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71838191-10d0-497f-8399-7b533ebd4e0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Re-run only tests that failed last time

2015-03-24 Thread Russell Keith-Magee
Hi Gergely,

One option is to use a test suite GUI tool, like cricket:

http://pybee.org/cricket

Cricket lets you view your entire test suite as a tree, select subsets of
the suite to run, see test results as the suite executes, and re-run the
failures from the previous execution.

Yours,
Russ Magee %-)


On Tue, Mar 24, 2015 at 6:27 PM, Gergely Polonkai 
wrote:

> Hello,
>
> I have a pretty extended test suite for my application, which can run for
> about 15 minutes. Now when I introduce an error, I will be notified of it
> pretty late, and a one-liner fix needs another 15 minutes to check. Of
> course if only one of my tests fail, I can add the name of the test case as
> a parameter to manage.py test, but in case of many failures it’s pretty
> hard to do the same.
>
> Is there a way to run only the tests that failed last time, even if I have
> to install a separate app/module for that? A quick Google search gave me no
> usable results.
>
> Best,
> Gergely
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACczBU%2B-SR3uASD_eQc_c%2BKFp%3DvCgaWga6pfUgA%2BJHr5HgkCHQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq84-hZn2VOe_dHRS63BXTmFJ8h3pbdsuKgQE1uFJo6csBZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Re-run only tests that failed last time

2015-03-24 Thread Gergely Polonkai
Hello Russ,

I've already installed the juno test runner, but a graphical tool cannot
hurt locally 😃 I'll check it out tomorrow, thanks for the link!

Best,
Gergely
On 24 Mar 2015 23:22, "Russell Keith-Magee"  wrote:

> Hi Gergely,
>
> One option is to use a test suite GUI tool, like cricket:
>
> http://pybee.org/cricket
>
> Cricket lets you view your entire test suite as a tree, select subsets of
> the suite to run, see test results as the suite executes, and re-run the
> failures from the previous execution.
>
> Yours,
> Russ Magee %-)
>
>
> On Tue, Mar 24, 2015 at 6:27 PM, Gergely Polonkai 
> wrote:
>
>> Hello,
>>
>> I have a pretty extended test suite for my application, which can run for
>> about 15 minutes. Now when I introduce an error, I will be notified of it
>> pretty late, and a one-liner fix needs another 15 minutes to check. Of
>> course if only one of my tests fail, I can add the name of the test case as
>> a parameter to manage.py test, but in case of many failures it’s pretty
>> hard to do the same.
>>
>> Is there a way to run only the tests that failed last time, even if I
>> have to install a separate app/module for that? A quick Google search gave
>> me no usable results.
>>
>> Best,
>> Gergely
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACczBU%2B-SR3uASD_eQc_c%2BKFp%3DvCgaWga6pfUgA%2BJHr5HgkCHQ%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJxq84-hZn2VOe_dHRS63BXTmFJ8h3pbdsuKgQE1uFJo6csBZw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBULt18gAbJT1-1OWEd2Xy%2Bsk-201%3D%2Bs1EYgJ9zveyo-Uaw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Re-run only tests that failed last time

2015-03-24 Thread Carl Meyer
Hi Gergely,

On 03/24/2015 04:27 AM, Gergely Polonkai wrote:
> I have a pretty extended test suite for my application, which can run
> for about 15 minutes. Now when I introduce an error, I will be notified
> of it pretty late, and a one-liner fix needs another 15 minutes to
> check. Of course if only one of my tests fail, I can add the name of the
> test case as a parameter to manage.py test, but in case of many failures
> it’s pretty hard to do the same.
> 
> Is there a way to run only the tests that failed last time, even if I
> have to install a separate app/module for that? A quick Google search
> gave me no usable results.

I use py.test [1], another test runner which has plugins that offer this
feature. The pytest-django [2] plugin provides the necessary integration
to make py.test able to run a normal Django test suite. Then the
pytest-cache [3] plugin offers an ``--lf`` (last-failed) option to run
only the tests that failed in the last run, and the pytest-xdist [4]
plugin offers the even-more-advanced ``--looponfail`` option, which "run
your tests repeatedly in a subprocess. After each run py.test waits
until a file in your project changes and then re-runs the previously
failing tests. This is repeated until all tests pass after which again a
full run is performed."

If you're interested in advanced Python testing, I think py.test is near
the top of the list of tools you should at least take for a spin.

Carl

[1] http://pytest.org/latest/
[2] https://pypi.python.org/pypi/pytest-django/
[3] https://pypi.python.org/pypi/pytest-cache
[4] https://bitbucket.org/pytest-dev/pytest-xdist

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5511E627.8090409%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


how to initiate an interactive python script from an html cgi?

2015-03-24 Thread arthur sherman
i have a python script which currently runs in a shell cli.
i'd like to initiate this script from a web page.
the closest i got was to have the output displayed on the webpage (w/o 
linefeeds),
but it crashed when requesting input via raw_input().
i simply did 'exec python-script-name' from the cgi.
ok, i now understand why it crashed and why the output is displayed 
primitively
it's  now my understanding that django can help.
where's the best place to start?
tnx
ams

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/83facec0-80cd-4b6d-bd5c-ec5d6798056c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: image handling

2015-03-24 Thread Akash Patni
Hi,
I have added the code to my  __init__.py file but still its not working.

__init__.py
from django.core.files.storage import default_storage as storage
from django.db.models.signals import pre_save
from django.db import models
import django.forms as forms
from django.contrib.auth.models import User

def image_delete(sender, instance, *args, **kwargs):
  if instance.pk:
old_instance = User.objects.get(pk=instance.pk)

if old_instance.image != instance.image and instance.image:
  storage.delete(old_instance.image.name)
  pre_save.connect(image_delete, sender=User)

model.py

class User(models.Model):
first_name=models.CharField(verbose_name = "First Name
*",max_length=20,blank=False)
last_name=models.CharField(verbose_name = "Last Name
*",max_length=20,blank=False)
username=models.EmailField(verbose_name = "Email
*",max_length=30,blank=False)
password=models.CharField(verbose_name = "Password
*",max_length=15,blank=False)
dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
mobileno=models.CharField(verbose_name = "Mobile No
*",max_length=20,blank=False)
houseno=models.CharField(verbose_name = "House
No",max_length=10,blank=True)
address1=models.CharField(verbose_name =
"Adress1",max_length=30,blank=True)
city=models.CharField(verbose_name = "City",max_length=20,blank=True)
state=models.CharField(verbose_name = "State",max_length=30,blank=True)
pincode=models.CharField(verbose_name =
"Pincode",max_length=20,blank=True)
country=models.CharField(verbose_name =
"Country",max_length=30,blank=True)
comment=models.CharField(verbose_name =
"Comment",max_length=200,blank=True)
sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
image=models.FileField(verbose_name = "Image(limit 1Mb)
*",blank=True,upload_to=path_and_rename(''))

def __unicode__(self):
return self.first_name


On Tue, Mar 24, 2015 at 7:44 PM, Andreas Kuhne 
wrote:

> First, make sure that the whitespace is the same in all of your methods
> (in python whitespace is significant, which means that you should indent
> all files the same amount, I wrote my example in my email, so I only
> indented twice, you seem to have 4 blankspaces in your file, so make sure
> the indentation is the same).
>
> Secondly, I think that you should add the code I sent to the __init__.py
> file in the project itself (in the same directory that you have you
> models.py). That way it will be run during startup (which needs to be done).
>
> Regards,
>
> Andréas
>
> 2015-03-24 14:20 GMT+01:00 Akash Patni :
>
>> i had made the changes in model .py but its not working
>>
>> here is model.py
>>
>>
>> from django.db import models
>> import django.forms as forms
>> from virtualenv import REQUIRED_FILES
>> from _mysql import NULL
>> from datetime import datetime, date, time, timedelta
>> import time
>> import calendar
>> from django.contrib.auth.models import User
>> import os
>> from uuid import uuid4
>> from django.core.files.storage import default_storage as storage
>> from django.db.models.signals import pre_save
>>
>>
>> def path_and_rename(path):
>> def wrapper(instance, filename):
>> ext = filename.split('.')[-1]
>> # get filename
>> if instance.pk:
>> filename = '{}.{}'.format(instance.pk, ext)
>> else:
>> # set filename as random string
>> filename = '{}.{}'.format(uuid4().hex, ext)
>> # return the whole path to the file
>> return os.path.join(path, filename)
>> return wrapper
>>
>> def image_delete(sender, instance, *args, **kwargs):
>>   if instance.pk:
>> old_instance = User.objects.get(pk=instance.pk)
>>
>> if old_instance.image != instance.image and instance.image:
>>   storage.delete(old_instance.image.name)
>>
>> pre_save.connect(image_delete, sender=User)
>>
>> class Publisher(models.Model):
>> name = models.CharField(max_length=30)
>> address = models.CharField(max_length=50)
>> city = models.CharField(max_length=60)
>> state_province = models.CharField(max_length=30)
>> country = models.CharField(max_length=50)
>> website = models.URLField()
>>
>> def __unicode__(self):
>> return self.name
>>
>> class Author(models.Model):
>> first_name = models.CharField(max_length=30)
>> last_name = models.CharField(max_length=40)
>> email = models.EmailField()
>>
>> def __unicode__(self):
>> return u'%s %s' % (self.first_name, self.last_name)
>>
>> class Book(models.Model):
>> title = models.CharField(max_length=100)
>> authors = models.ManyToManyField(Author)
>> publisher = models.ForeignKey(Publisher)
>> publication_date = models.DateField()
>>
>> def __unicode__(self):
>> return self.title
>>
>> class User(models.Model):
>> first_name=models.CharField(verbose_name = "First Name
>> *",max_length=20,blank=False)
>> last_name=models.CharField(verbose_name = "Last N

Re: image handling

2015-03-24 Thread Akash Patni
Hi,
Can i use this method in my model.py

def save(self, *args, **kwargs):
try:
this = MyModelName.objects.get(id=self.id)
if this.MyImageFieldName != self.MyImageFieldName:
this.MyImageFieldName.delete()
except: pass
super(MyModelName, self).save(*args, **kwargs)


class User(models.Model):

  image=models.FileField(verbose_name = "Image(limit 1Mb)
*",blank=True,upload_to=path_and_rename('')*,storage=save('self')*)

  def __unicode__(self):
return self.first_name
i have doubt about storage in my file field which i have
highlighted. Is it right, Please sugges.



On Wed, Mar 25, 2015 at 9:28 AM, Akash Patni 
wrote:

> Hi,
> I have added the code to my  __init__.py file but still its not working.
>
> __init__.py
> from django.core.files.storage import default_storage as storage
> from django.db.models.signals import pre_save
> from django.db import models
> import django.forms as forms
> from django.contrib.auth.models import User
>
> def image_delete(sender, instance, *args, **kwargs):
>   if instance.pk:
> old_instance = User.objects.get(pk=instance.pk)
>
> if old_instance.image != instance.image and instance.image:
>   storage.delete(old_instance.image.name)
>   pre_save.connect(image_delete, sender=User)
>
> model.py
>
> class User(models.Model):
> first_name=models.CharField(verbose_name = "First Name
> *",max_length=20,blank=False)
> last_name=models.CharField(verbose_name = "Last Name
> *",max_length=20,blank=False)
> username=models.EmailField(verbose_name = "Email
> *",max_length=30,blank=False)
> password=models.CharField(verbose_name = "Password
> *",max_length=15,blank=False)
> dob=models.DateField(verbose_name = "DOB *" ,blank=True,null=True)
> mobileno=models.CharField(verbose_name = "Mobile No
> *",max_length=20,blank=False)
> houseno=models.CharField(verbose_name = "House
> No",max_length=10,blank=True)
> address1=models.CharField(verbose_name =
> "Adress1",max_length=30,blank=True)
> city=models.CharField(verbose_name = "City",max_length=20,blank=True)
> state=models.CharField(verbose_name = "State",max_length=30,blank=True)
> pincode=models.CharField(verbose_name =
> "Pincode",max_length=20,blank=True)
> country=models.CharField(verbose_name =
> "Country",max_length=30,blank=True)
> comment=models.CharField(verbose_name =
> "Comment",max_length=200,blank=True)
> sex=models.CharField(verbose_name = "Sex *",max_length=5,blank=False)
> image=models.FileField(verbose_name = "Image(limit 1Mb)
> *",blank=True,upload_to=path_and_rename(''))
>
> def __unicode__(self):
> return self.first_name
>
>
> On Tue, Mar 24, 2015 at 7:44 PM, Andreas Kuhne  > wrote:
>
>> First, make sure that the whitespace is the same in all of your methods
>> (in python whitespace is significant, which means that you should indent
>> all files the same amount, I wrote my example in my email, so I only
>> indented twice, you seem to have 4 blankspaces in your file, so make sure
>> the indentation is the same).
>>
>> Secondly, I think that you should add the code I sent to the __init__.py
>> file in the project itself (in the same directory that you have you
>> models.py). That way it will be run during startup (which needs to be done).
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-03-24 14:20 GMT+01:00 Akash Patni :
>>
>>> i had made the changes in model .py but its not working
>>>
>>> here is model.py
>>>
>>>
>>> from django.db import models
>>> import django.forms as forms
>>> from virtualenv import REQUIRED_FILES
>>> from _mysql import NULL
>>> from datetime import datetime, date, time, timedelta
>>> import time
>>> import calendar
>>> from django.contrib.auth.models import User
>>> import os
>>> from uuid import uuid4
>>> from django.core.files.storage import default_storage as storage
>>> from django.db.models.signals import pre_save
>>>
>>>
>>> def path_and_rename(path):
>>> def wrapper(instance, filename):
>>> ext = filename.split('.')[-1]
>>> # get filename
>>> if instance.pk:
>>> filename = '{}.{}'.format(instance.pk, ext)
>>> else:
>>> # set filename as random string
>>> filename = '{}.{}'.format(uuid4().hex, ext)
>>> # return the whole path to the file
>>> return os.path.join(path, filename)
>>> return wrapper
>>>
>>> def image_delete(sender, instance, *args, **kwargs):
>>>   if instance.pk:
>>> old_instance = User.objects.get(pk=instance.pk)
>>>
>>> if old_instance.image != instance.image and instance.image:
>>>   storage.delete(old_instance.image.name)
>>>
>>> pre_save.connect(image_delete, sender=User)
>>>
>>> class Publisher(models.Model):
>>> name = models.CharField(max_length=30)
>>> address = models.CharField(max_length=50)
>>> city = models.CharField(max_length=60)
>>> state_province = models.CharField(max_length=30)
>>> country = models.CharFie