Dutch translation of Django Tutorial

2014-10-25 Thread Tomáš Ehrlich
Hello everyone,
there are two things that going to happen in next month:

1. Django Under the Hood conference in Amsterdam
2. (Hopefully) I’ll finish SaaS for managing translations. The first frontend 
build on top of gettext message catalogues will be for Sphinx documentation.

As a result, I would like make dutch translation of django documentation. 
Unfortunately, as Django docs are pretty comprehensive, I don’t think it’s 
possible to translate everything in three weeks. Therefore, I want to focus on 
tutorial which is a the best starting point for beginners.

I’ve already found a English->Dutch translator who is available.


The questions are:

1. Is there any Dutch translation already available? I’m aware of French and 
Czech translation, there are few more in transifex 
https://www.transifex.com/projects/p/django-docs/, but I haven’t found any 
references about Dutch one.
2. Are there any Dutch developers willing to review the translation?


Thank you in advance,
   Tom

-- 
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/etPan.544b8aee.238e1f29.9f79%40issac.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with Pillow image resize and save

2014-10-25 Thread Daniel Grace
I need to include the following steps, but I don't know how:
1. copy the 'picture' file
2. resize it (the copy)
3. save it to the upload directory
4. store it in the 'thumb' field
... continue as before and save the 'profile'.

-- 
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/e4333b8c-f3c1-4661-a83e-034bcbf3a8d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Merge two Databases into one

2014-10-25 Thread Majo
Larry's right, if it's a one time thing, use

mysqldump -u YOUR_DB_USER -p OLD_DB --no-create-info > SOME_FILE.sql

from the command line. Then, to import, use:
mysqlimport -u YOUR_DB_USER -p NEW_DB SOME_FILE.sql

To be sure you understand what's happening, check the docs first:

http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html
and
http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html

Also, don't forget to create a backup of your new_db (by using mysqldump as 
described above, just without the --no-create-info)


Unrelated to your question, but you might also want to consider to upgrade 
your Django installation to something newer than 1.3 ;)


On Friday, October 24, 2014 7:17:12 PM UTC+2, Ram Ganesh wrote:
>
> Hi all,
>
> I want to append my datas from old_db to new_db
> they have exactly the same structure,
>
> I'm trying to Write a Script using Django Manually selecting a database
>   -Read data from old_db and Write it into new_db 
>   -But not sure its work fine with maintaining foreign key relationships.
>
> what do you think would be the best solution for my problem?
>
> using MySql,
> Django 1.3
>
> Thanks,
> Ram Ganesh K
>

-- 
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/6e90c27c-488f-4cbc-b350-9b93a21f936a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "autocommit cannot be used inside a transaction" error: trying to use a custom form with a CreateView

2014-10-25 Thread Michael
After furthing testing, I removed django_postgrespool 
(DATABASES['default']['ENGINE'] = 'django_postgrespool') and the error was 
finally more explicit about an integrity error. I was able to fix it and 
the error was gone.

Why the error is not the actual error when using django_postgrespool?

Thanks

-- 
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/da184a09-5890-48a5-8bfb-d67c4df36540%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to get related data on one to one field of a foreign key?

2014-10-25 Thread Daniel Grace
Hi,
I have a log table with a foreign key to the user table, and a userprofile 
table with a one to one field to the user table:

class Log(models.Model):
user = models.ForeignKey(User)
...

class UserProfile(models.Model):
user = models.OneToOneField(User)
picture = models.ImageField(upload_to='profile_images', blank=True)
... 

In my ListView I want to get the user profile for each log.  I know I can 
use select_related to get the related users of the log as follows:
queryset = Log.objects.select_related('user').order_by('created')

... but how do I get the related profiles and pass these on to the 
template, so I can for example display the picture for each log?

Thanks

-- 
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/5f2e11e0-bb82-4280-a63e-f90560ca37bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to get related data on one to one field of a foreign key?

2014-10-25 Thread Daniel Roseman
That's what you've already done with your select_related call. What you should 
have asked is how you access that data in the template, and the answer is that 
you simply follow the relationship from your Log object:

{% for log in logs %}
{{ log.myfield }}
{{ log.userprofile.picture }}
{% endfor %}

-- 
DR.

-- 
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/8a1f73c2-03ae-46b6-a9fa-58ef4f4716c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Integer Form with Select Widget?

2014-10-25 Thread Farhan Khan
Hi all,

I want to get an Integer value from the user through a forms.Form. I have 
three unique requirements for it.

   1. The corresponding Widget is Select or SelectMultiple (either one)
   2. The 'choices' field is dynamic, not static or hard-coded -they are 
   adjusted upon each display of the Form based on program logic.
   3. I want the max_value and min_value of IntegerField to also be dynamic 
   - also adjusted based on program logic.
   

What I have thus far is this:

class deleteUserForm(forms.Form):
   delUserId = forms.CharField(label='delUserId', widget=forms.Select)

How would this work?

Thanks
- Farhan

-- 
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/3c12eccc-a3b8-4108-83af-8288a2ccd998%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


TEST_MIRROR not working?

2014-10-25 Thread Ilya Baryshev
Hey all!

I was writing tests for queries that use replica database, so I tried using 
TEST_MIRROR 

 
setting.
TEST_MIRROR promises "connection to slave will be redirected to point at 
default. 
As a result, writes to default will appear on slave". Which happens not to 
be the case for me,
replica queries are not returning expected results.

Is this a bug, or am I missing something?

Here is my example settings:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'testmirror',
'HOST': '127.0.0.1',
'PORT': 5432,
},
'slave': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'testmirror2',
'HOST': '127.0.0.1',
'PORT': 5432,
'TEST': {
'MIRROR': 'default'
}
}
}

And test that show replica doesn't have same data:

def test_fixture(self):
MyModel.objects.create(name=1)
self.assertEqual(MyModel.objects.using('default').count(),
 MyModel.objects.using('slave').count())

Example project in github: https://github.com/coagulant/test_mirror
My case can be repeated by simply running python manage.py test

I'm using

Django==1.7.1
psycopg2==2.5.4

-- 
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/a2b703df-3863-425d-871d-ceebe34c2625%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get related data on one to one field of a foreign key?

2014-10-25 Thread Daniel Grace
I just used the following:
{{ log.user.userprofile.picture }}
... and I didn't need the select_related.

-- 
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/bbed42ee-3ff4-4e8f-9790-fe0dee42031b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with Pillow image resize and save

2014-10-25 Thread John
On 25/10/14 15:26, Daniel Grace wrote:
> I need to include the following steps, but I don't know how:
> 1. copy the 'picture' file
> 2. resize it (the copy)
> 3. save it to the upload directory
> 4. store it in the 'thumb' field
> ... continue as before and save the 'profile'.
> -- 

Daniel,

I've done something similar for a simple image manager. I have a
WebImage object that holds references to an image and its thumbnail. The
thumbnail is created using imagemagick's convert function when the image
is updated. Extracts from models.py and admin.py shown below should give
you all the clues you need.

John

#
# models.py

from django.conf import settings
from django.db import models
from django.db.models import F, Q
import os
import uuid
import subprocess

_CONVERT_CMD = '/usr/bin/convert'
_CONVERT_THUMBNAIL_OPTS = ['-thumbnail','150x50']

# ...

class WebImage(models.Model):
  "Images that are used on the web pages. Limited to certain sizes. Can
be produced by an ImageGenerator."
  def get_image_file_path(inst, filename):
fn, ext = os.path.splitext(filename)
filename = "%s%s" % (uuid.uuid4(), ext)
return os.path.join(settings.MEDIA_ROOT+'wi/', filename)
 
  name = models.CharField(max_length=80,help_text="Full name of the web
image")
  slug = models.SlugField(max_length=50,help_text="Slug for the web
image name")
  description = models.TextField(help_text="Image description")
  img =
models.ImageField(null=True,upload_to=get_image_file_path,height_field="height",width_field="width")
  img_gen = models.ForeignKey('ImageGenerator', blank=True, null=True,
on_delete=models.SET_NULL)
  img_size = models.ForeignKey('ImageSize', blank=True, null=True,
default=None, on_delete=models.SET_NULL)
  width = models.IntegerField(editable=False,blank=True,help_text="Width
of the picture. Not editable")
  height =
models.IntegerField(editable=False,blank=True,help_text="Height of the
picture. Not editable")
  licensing = models.TextField(blank=True,help_text="Details of image
ownership, copyright and licensing. Blank for 'same as original image'")
  created_by = models.CharField(editable=False,blank=True,max_length=80,
help_text="Uploader. Not editable")
  creation_date =
models.DateTimeField(editable=False,blank=True,auto_now_add=True,
help_text="Date/time uploaded. Not editable")
  uploaded_by =
models.CharField(editable=False,blank=True,max_length=80,
help_text="Uploader. Not editable")
  upload_date =
models.DateTimeField(editable=False,blank=True,auto_now_add=True,
help_text="Date/time uploaded. Not editable")
  tags = TaggableManager()

  def thumb_path(self):
return
os.path.join(settings.MEDIA_ROOT+'thumb/',os.path.basename(self.img.name))

  def thumb_url(self):
return "%sthumb/%s" %
(settings.MEDIA_URL,os.path.basename(self.img.name))

  def create_thumb(self):
args = [_CONVERT_CMD, self.img.name] + _CONVERT_THUMBNAIL_OPTS +
[self.thumb_path()]
try:
  output = subprocess.call(args)
except subprocess.CalledProcessError, e:
  self.description = "%s\n%s\n%d" % (self.description, e.output,
e.returncode)
  pass # This needs to be a logger.
self.save()

  def thumb_field(self):
return ('' % self.thumb_url())
  thumb_field.short_description = "Thumbnail"
  thumb_field.allow_tags = True

  def get_absolute_url(self):
return "%swi/%s" % (settings.MEDIA_URL,os.path.split(self.img.name)[1])

  def __unicode__(self):
return "%s (%dx%d)" % (self.name,self.width,self.height)


# admin.py

class WebImageAdmin(ModelAdmin):
  def save_model(self, req, obj, form, change):
# Add the uploader info to the object
if not change or obj.uploaded_by == '':
  obj.uploaded_by = "%s (%s %s)" % (req.user.username,
req.user.first_name, req.user.last_name)
# And the creator info in the same manner
if not change or obj.created_by == '':
  obj.created_by = "%s (%s %s)" % (req.user.username,
req.user.first_name, req.user.last_name)
# And save
obj.save()
# Create a thumbnail
obj.create_thumb()

  list_display = ("__unicode__","img_size","thumb_field",)
  list_filter = ('img_size','width','height')
  ordering = ('name','width','height')
  prepopulated_fields = {"slug": ("name",)}
  save_on_top = True
 
  form = WebImageForm

-- 
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/544BEA38.2030801%40martinhome.org.uk.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with Pillow image resize and save

2014-10-25 Thread Aliane Abdelouahab
You have to send the picture editing to another process, because you will 
block the operation untill the image will be converted! 

Le samedi 25 octobre 2014 19:23:33 UTC+1, John a écrit :
>
>  On 25/10/14 15:26, Daniel Grace wrote:
>  
> I need to include the following steps, but I don't know how: 
> 1. copy the 'picture' file
> 2. resize it (the copy)
> 3. save it to the upload directory
> 4. store it in the 'thumb' field
> ... continue as before and save the 'profile'.
>  -- 
>
>
> Daniel,
>
> I've done something similar for a simple image manager. I have a WebImage 
> object that holds references to an image and its thumbnail. The thumbnail 
> is created using imagemagick's convert function when the image is updated. 
> Extracts from models.py and admin.py shown below should give you all the 
> clues you need.
>
> John
>
> #
> # models.py
>
> from django.conf import settings
> from django.db import models
> from django.db.models import F, Q
> import os
> import uuid
> import subprocess
>
> _CONVERT_CMD = '/usr/bin/convert'
> _CONVERT_THUMBNAIL_OPTS = ['-thumbnail','150x50']
>
> # ...
>
> class WebImage(models.Model):
>   "Images that are used on the web pages. Limited to certain sizes. Can be 
> produced by an ImageGenerator."
>   def get_image_file_path(inst, filename):
> fn, ext = os.path.splitext(filename)
> filename = "%s%s" % (uuid.uuid4(), ext)
> return os.path.join(settings.MEDIA_ROOT+'wi/', filename)
>   
>   name = models.CharField(max_length=80,help_text="Full name of the web 
> image")
>   slug = models.SlugField(max_length=50,help_text="Slug for the web image 
> name")
>   description = models.TextField(help_text="Image description")
>   img = 
> models.ImageField(null=True,upload_to=get_image_file_path,height_field="height",width_field="width")
>   img_gen = models.ForeignKey('ImageGenerator', blank=True, null=True, 
> on_delete=models.SET_NULL)
>   img_size = models.ForeignKey('ImageSize', blank=True, null=True, 
> default=None, on_delete=models.SET_NULL)
>   width = models.IntegerField(editable=False,blank=True,help_text="Width 
> of the picture. Not editable")
>   height = models.IntegerField(editable=False,blank=True,help_text="Height 
> of the picture. Not editable")
>   licensing = models.TextField(blank=True,help_text="Details of image 
> ownership, copyright and licensing. Blank for 'same as original image'")
>   created_by = models.CharField(editable=False,blank=True,max_length=80, 
> help_text="Uploader. Not editable")
>   creation_date = 
> models.DateTimeField(editable=False,blank=True,auto_now_add=True, 
> help_text="Date/time uploaded. Not editable")
>   uploaded_by = models.CharField(editable=False,blank=True,max_length=80, 
> help_text="Uploader. Not editable")
>   upload_date = 
> models.DateTimeField(editable=False,blank=True,auto_now_add=True, 
> help_text="Date/time uploaded. Not editable")
>   tags = TaggableManager()
>
>   def thumb_path(self):
> return os.path.join(settings.MEDIA_ROOT+'thumb/',os.path.basename(
> self.img.name))
>
>   def thumb_url(self):
> return "%sthumb/%s" % (settings.MEDIA_URL,os.path.basename(
> self.img.name))
>
>   def create_thumb(self):
> args = [_CONVERT_CMD, self.img.name] + _CONVERT_THUMBNAIL_OPTS + 
> [self.thumb_path()]
> try:
>   output = subprocess.call(args)
> except subprocess.CalledProcessError, e:
>   self.description = "%s\n%s\n%d" % (self.description, e.output, 
> e.returncode) 
>   pass # This needs to be a logger.
> self.save()
>
>   def thumb_field(self):
> return ('' % self.thumb_url())
>   thumb_field.short_description = "Thumbnail"
>   thumb_field.allow_tags = True
>
>   def get_absolute_url(self):
> return "%swi/%s" % (settings.MEDIA_URL,os.path.split(self.img.name
> )[1])
>
>   def __unicode__(self):
> return "%s (%dx%d)" % (self.name,self.width,self.height)
>
> 
> # admin.py
>
> class WebImageAdmin(ModelAdmin):
>   def save_model(self, req, obj, form, change):
> # Add the uploader info to the object
> if not change or obj.uploaded_by == '':
>   obj.uploaded_by = "%s (%s %s)" % (req.user.username, 
> req.user.first_name, req.user.last_name)
> # And the creator info in the same manner
> if not change or obj.created_by == '':
>   obj.created_by = "%s (%s %s)" % (req.user.username, 
> req.user.first_name, req.user.last_name)
> # And save
> obj.save()
> # Create a thumbnail
> obj.create_thumb()
>
>   list_display = ("__unicode__","img_size","thumb_field",)
>   list_filter = ('img_size','width','height')
>   ordering = ('name','width','height')
>   prepopulated_fields = {"slug": ("name",)}
>   save_on_top = True
>   
>   form = WebImageForm
>
> 

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

Re: Problem with Pillow image resize and save

2014-10-25 Thread John
That's a good idea, Aliane. In my case, the server was lightly loaded,
the conversion time is very short and the admin was only used by a very
small number of users who were sufficiently patient.

John

On 25/10/14 20:23, Aliane Abdelouahab wrote:
> You have to send the picture editing to another process, because you
> will block the operation untill the image will be converted! 
>
> Le samedi 25 octobre 2014 19:23:33 UTC+1, John a écrit :
>
> On 25/10/14 15:26, Daniel Grace wrote:
>> I need to include the following steps, but I don't know how:
>> 1. copy the 'picture' file
>> 2. resize it (the copy)
>> 3. save it to the upload directory
>> 4. store it in the 'thumb' field
>> ... continue as before and save the 'profile'.
>> -- 
>
> Daniel,
>
> I've done something similar for a simple image manager. I have a
> WebImage object that holds references to an image and its
> thumbnail. The thumbnail is created using imagemagick's convert
> function when the image is updated. Extracts from models.py and
> admin.py shown below should give you all the clues you need.
>
> John
>
> #
> # models.py
>
> from django.conf import settings
> from django.db import models
> from django.db.models import F, Q
> import os
> import uuid
> import subprocess
>
> _CONVERT_CMD = '/usr/bin/convert'
> _CONVERT_THUMBNAIL_OPTS = ['-thumbnail','150x50']
>
> # ...
>
> class WebImage(models.Model):
>   "Images that are used on the web pages. Limited to certain
> sizes. Can be produced by an ImageGenerator."
>   def get_image_file_path(inst, filename):
> fn, ext = os.path.splitext(filename)
> filename = "%s%s" % (uuid.uuid4(), ext)
> return os.path.join(settings.MEDIA_ROOT+'wi/', filename)
>  
>   name = models.CharField(max_length=80,help_text="Full name of
> the web image")
>   slug = models.SlugField(max_length=50,help_text="Slug for the
> web image name")
>   description = models.TextField(help_text="Image description")
>   img =
> 
> models.ImageField(null=True,upload_to=get_image_file_path,height_field="height",width_field="width")
>   img_gen = models.ForeignKey('ImageGenerator', blank=True,
> null=True, on_delete=models.SET_NULL)
>   img_size = models.ForeignKey('ImageSize', blank=True, null=True,
> default=None, on_delete=models.SET_NULL)
>   width =
> models.IntegerField(editable=False,blank=True,help_text="Width of
> the picture. Not editable")
>   height =
> models.IntegerField(editable=False,blank=True,help_text="Height of
> the picture. Not editable")
>   licensing = models.TextField(blank=True,help_text="Details of
> image ownership, copyright and licensing. Blank for 'same as
> original image'")
>   created_by =
> models.CharField(editable=False,blank=True,max_length=80,
> help_text="Uploader. Not editable")
>   creation_date =
> models.DateTimeField(editable=False,blank=True,auto_now_add=True,
> help_text="Date/time uploaded. Not editable")
>   uploaded_by =
> models.CharField(editable=False,blank=True,max_length=80,
> help_text="Uploader. Not editable")
>   upload_date =
> models.DateTimeField(editable=False,blank=True,auto_now_add=True,
> help_text="Date/time uploaded. Not editable")
>   tags = TaggableManager()
>
>   def thumb_path(self):
> return
> os.path.join(settings.MEDIA_ROOT+'thumb/',os.path.basename(self.img.name
> ))
>
>   def thumb_url(self):
> return "%sthumb/%s" %
> (settings.MEDIA_URL,os.path.basename(self.img.name
> ))
>
>   def create_thumb(self):
> args = [_CONVERT_CMD, self.img.name ] +
> _CONVERT_THUMBNAIL_OPTS + [self.thumb_path()]
> try:
>   output = subprocess.call(args)
> except subprocess.CalledProcessError, e:
>   self.description = "%s\n%s\n%d" % (self.description,
> e.output, e.returncode)
>   pass # This needs to be a logger.
> self.save()
>
>   def thumb_field(self):
> return ('' % self.thumb_url())
>   thumb_field.short_description = "Thumbnail"
>   thumb_field.allow_tags = True
>
>   def get_absolute_url(self):
> return "%swi/%s" %
> (settings.MEDIA_URL,os.path.split(self.img.name
> )[1])
>
>   def __unicode__(self):
> return "%s (%dx%d)" % (self.name
> ,self.width,self.height)
>
> 
> # admin.py
>
> class WebImageAdmin(ModelAdmin):
>   def save_model(self, req, obj, form, change):
> # Add the uploader info to the object
> if not change or obj.uploaded_by == '':
>   obj.uploaded_by = "%s (%s %s)" % (req.user.username,
> req.user.first_name, req.user.last_name)
> 

Re: New way to use URL dispatchers?

2014-10-25 Thread Carl Meyer

> On Oct 24, 2014, at 8:37 PM, Russell Keith-Magee  
> wrote:
> 
> When it is released, Django 1.8 will include support for the new preferred 
> format for URLpatterns. Django 1.7 doesn't support this new format, and the 
> documentation for version 1.7:
> 
> https://docs.djangoproject.com/en/1.7/ref/urls/#patterns 
> 
> 
> doesn't mention the new format. 

Small clarification: the “new” way (urlpatterns just a list of urls) actually 
works just fine in 1.7, 1.6, and earlier versions of Django too (as long as you 
use the `url(…)` function to define each url, and import your views rather than 
referencing them as strings). So you can switch to it right now, regardless of 
what Django version you are using.

The 1.7 docs still use the `patterns(…)` function (which is deprecated starting 
in 1.8) simply in order to maintain compatibility with the output of 1.7’s 
startproject command.

Carl

-- 
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/DC80BF90-C479-4098-A072-A0E1A7E22171%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


migrate and runserver commands hang, there is no traceback, no clue yet why (1.7.1)

2014-10-25 Thread JJ Zolper
I really wish I could give some useful information in the terms of a 
traceback so others may have an idea what is happening to me but I'm 
completely serious when I say I don't even get a traceback right now. Here 
is the break down of what I did to give an idea of how I ended up at this 
point, hopefully. I will continue to try to iterate upon this discussion as 
well through observations to try to work on my own or with others to get 
down to the cause of the issue.

First with a clean and empty database I ran the migrate command and 
everything went fine. There were no issues as it ran through:

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py migrate

*Operations to perform:*

*  Synchronize unmigrated apps: *colleges, ads, debug_toolbar, comments, 
communities, main, athletes, ad_manager

*  Apply all migrations: *admin, contenttypes, sites, auth, sessions

*Synchronizing apps without migrations:*

  Creating tables...

Creating table athletes_athlete_athletecolleges

Creating table athletes_athlete_athletecommunities

Creating table athletes_athlete

Creating table athletes_registrationprofile

Creating table colleges_college

Creating table colleges_collegeevent_attendees

Creating table colleges_collegeevent

Creating table communities_community

Creating table communities_country

Creating table communities_city

Creating table communities_communitypost_city

Creating table communities_communitypost_country

Creating table communities_communitypost

Creating table comments

Creating table comment_flags

Creating table main_teammember

Creating table ads_partner

Creating table ads_ad

Creating table ad_manager_target

Creating table ad_manager_adgroup

Creating table ad_manager_ad

Creating table ad_manager_pagetype

Creating table ad_manager_adtype

Creating table ad_manager_tagtype

  Installing custom SQL...

  Installing indexes...

*Running migrations:*

  Applying contenttypes.0001_initial...* OK*

  Applying auth.0001_initial...* OK*

  Applying admin.0001_initial...* OK*

  Applying sessions.0001_initial...* OK*

  Applying sites.0001_initial...* OK*


Next up I called to create a super user and that went fine as well:

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
createsuperuser

Username (leave blank to use 'jjz'): 

Email address: 

Password: 

Password (again): 

Superuser created successfully.


Then I ran the makemigrations command for the respective apps and their 
models that I wanted to have:

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
makemigrations colleges

*Migrations for 'colleges':*

  *0001_initial.py*:

- Create model College

- Create model CollegeEvent

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
makemigrations ads

*Migrations for 'ads':*

  *0001_initial.py*:

- Create model Ad

- Create model Partner

- Add field partner to ad

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
makemigrations comments

*Migrations for 'comments':*

  *0001_initial.py*:

- Create model Comment

- Create model CommentFlag

- Alter unique_together for commentflag (1 constraint(s))

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
makemigrations communities

*Migrations for 'communities':*

  *0001_initial.py*:

- Create model City

- Create model Community

- Create model CommunityPost

- Create model Country

- Add field country to communitypost

- Add field user to communitypost

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
makemigrations main

*Migrations for 'main':*

  *0001_initial.py*:

- Create model TeamMember

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
makemigrations athletes

*Migrations for 'athletes':*

  *0001_initial.py*:

- Create model Athlete

- Create model RegistrationProfile


Up until this point I had no concerns, things seemed to be working as 
expected, but what happened next stunned me. The migrate command hung it 
just sat there seemingly doing nothing. I hit command c to cancel because 
I'm on a mac thinking maybe I had done something wrong and it wouldn't 
happen again but it continues.

I tried to run runserver next:

(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py runserver

Performing system checks...


System check identified no issues (0 silenced).

^C(zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py migrate

^C


As you can see it hung and I had to cancel and hit command c on both 
runserver and the following migrate.

Sorry for the wall of text but I just want to put this all out there in 
case it gives any awareness. Anyways, here is my speculation to what is 
causing the "endless loop" within my models, I say this because I didn't 
have this issue up until I started messing with this part of my models. 
Here is o

Re: migrate and runserver commands hang, there is no traceback, no clue yet why (1.7.1)

2014-10-25 Thread Carl Meyer
Hi JJ,

One thing that can cause hangs when running migrations is having another 
process (say a ‘manage.py shell’) with a connection to the same database 
sitting open, possibly with a transaction in progress that is holding locks on 
the tables the migrations need to touch. Any possibility that’s what happened 
here?

Carl

> On Oct 25, 2014, at 2:23 PM, JJ Zolper  wrote:
> 
> I really wish I could give some useful information in the terms of a 
> traceback so others may have an idea what is happening to me but I'm 
> completely serious when I say I don't even get a traceback right now. Here is 
> the break down of what I did to give an idea of how I ended up at this point, 
> hopefully. I will continue to try to iterate upon this discussion as well 
> through observations to try to work on my own or with others to get down to 
> the cause of the issue.
> 
> First with a clean and empty database I ran the migrate command and 
> everything went fine. There were no issues as it ran through:
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py migrate
> 
> Operations to perform:
> 
>   Synchronize unmigrated apps: colleges, ads, debug_toolbar, comments, 
> communities, main, athletes, ad_manager
> 
>   Apply all migrations: admin, contenttypes, sites, auth, sessions
> 
> Synchronizing apps without migrations:
> 
>   Creating tables...
> 
> Creating table athletes_athlete_athletecolleges
> 
> Creating table athletes_athlete_athletecommunities
> 
> Creating table athletes_athlete
> 
> Creating table athletes_registrationprofile
> 
> Creating table colleges_college
> 
> Creating table colleges_collegeevent_attendees
> 
> Creating table colleges_collegeevent
> 
> Creating table communities_community
> 
> Creating table communities_country
> 
> Creating table communities_city
> 
> Creating table communities_communitypost_city
> 
> Creating table communities_communitypost_country
> 
> Creating table communities_communitypost
> 
> Creating table comments
> 
> Creating table comment_flags
> 
> Creating table main_teammember
> 
> Creating table ads_partner
> 
> Creating table ads_ad
> 
> Creating table ad_manager_target
> 
> Creating table ad_manager_adgroup
> 
> Creating table ad_manager_ad
> 
> Creating table ad_manager_pagetype
> 
> Creating table ad_manager_adtype
> 
> Creating table ad_manager_tagtype
> 
>   Installing custom SQL...
> 
>   Installing indexes...
> 
> Running migrations:
> 
>   Applying contenttypes.0001_initial... OK
> 
>   Applying auth.0001_initial... OK
> 
>   Applying admin.0001_initial... OK
> 
>   Applying sessions.0001_initial... OK
> 
>   Applying sites.0001_initial... OK
> 
> 
> 
> Next up I called to create a super user and that went fine as well:
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> createsuperuser
> 
> Username (leave blank to use 'jjz'): 
> 
> Email address: 
> 
> Password: 
> 
> Password (again): 
> 
> 
> Superuser created successfully.
> 
> 
> 
> Then I ran the makemigrations command for the respective apps and their 
> models that I wanted to have:
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations colleges
> 
> Migrations for 'colleges':
> 
>   0001_initial.py:
> 
> - Create model College
> 
> - Create model CollegeEvent
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations ads
> 
> Migrations for 'ads':
> 
>   0001_initial.py:
> 
> - Create model Ad
> 
> - Create model Partner
> 
> - Add field partner to ad
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations comments
> 
> Migrations for 'comments':
> 
>   0001_initial.py:
> 
> - Create model Comment
> 
> - Create model CommentFlag
> 
> - Alter unique_together for commentflag (1 constraint(s))
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations communities
> 
> Migrations for 'communities':
> 
>   0001_initial.py:
> 
> - Create model City
> 
> - Create model Community
> 
> - Create model CommunityPost
> 
> - Create model Country
> 
> - Add field country to communitypost
> 
> - Add field user to communitypost
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations main
> 
> Migrations for 'main':
> 
>   0001_initial.py:
> 
> - Create model TeamMember
> 
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations athletes
> 
> Migrations for 'athletes':
> 
>   0001_initial.py:
> 
> - Create model Athlete
> 
> 
> - Create model RegistrationProfile
> 
> 
> 
> Up until this point I had no concerns, things seemed to be working as 
> expected, but what happened next stunned me. The migrate command hung it just 
> sat there seemingly doing nothing. I hit command c to cancel because I'm on a 
> mac thinking maybe I had done something wr

Re: New way to use URL dispatchers?

2014-10-25 Thread Aliane Abdelouahab
ah! thank you, because this is the 'cleanest' way, espetially for a 
beginner.
thank you :)

Le samedi 25 octobre 2014 21:04:49 UTC+1, Carl Meyer a écrit :
>
>
> On Oct 24, 2014, at 8:37 PM, Russell Keith-Magee  > wrote:
>
> When it is released, Django 1.8 will include support for the new preferred 
> format for URLpatterns. Django 1.7 doesn't support this new format, and the 
> documentation for version 1.7:
>
> https://docs.djangoproject.com/en/1.7/ref/urls/#patterns
>
> doesn't mention the new format. 
>
>
> Small clarification: the “new” way (urlpatterns just a list of urls) 
> actually works just fine in 1.7, 1.6, and earlier versions of Django too 
> (as long as you use the `url(…)` function to define each url, and import 
> your views rather than referencing them as strings). So you can switch to 
> it right now, regardless of what Django version you are using.
>
> The 1.7 docs still use the `patterns(…)` function (which is deprecated 
> starting in 1.8) simply in order to maintain compatibility with the output 
> of 1.7’s startproject command.
>
> Carl
>

-- 
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/2a65c7b9-ded6-410c-b357-0023a6618d79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem with Pillow image resize and save

2014-10-25 Thread Aliane Abdelouahab
ah, ok :)
just as another idea, you can handle the image uploads with Nginx, this 
will free Python from dealing static files.

Le samedi 25 octobre 2014 20:31:35 UTC+1, John a écrit :
>
>  That's a good idea, Aliane. In my case, the server was lightly loaded, 
> the conversion time is very short and the admin was only used by a very 
> small number of users who were sufficiently patient.
>
> John
>
> On 25/10/14 20:23, Aliane Abdelouahab wrote:
>  
> You have to send the picture editing to another process, because you will 
> block the operation untill the image will be converted! 
>
> Le samedi 25 octobre 2014 19:23:33 UTC+1, John a écrit : 
>>
>>  On 25/10/14 15:26, Daniel Grace wrote:
>>  
>> I need to include the following steps, but I don't know how: 
>> 1. copy the 'picture' file
>> 2. resize it (the copy)
>> 3. save it to the upload directory
>> 4. store it in the 'thumb' field
>> ... continue as before and save the 'profile'.
>>  -- 
>>
>>
>> Daniel,
>>
>> I've done something similar for a simple image manager. I have a WebImage 
>> object that holds references to an image and its thumbnail. The thumbnail 
>> is created using imagemagick's convert function when the image is updated. 
>> Extracts from models.py and admin.py shown below should give you all the 
>> clues you need.
>>
>> John
>>
>> #
>> # models.py
>>
>> from django.conf import settings
>> from django.db import models
>> from django.db.models import F, Q
>> import os
>> import uuid
>> import subprocess
>>
>> _CONVERT_CMD = '/usr/bin/convert'
>> _CONVERT_THUMBNAIL_OPTS = ['-thumbnail','150x50']
>>
>> # ...
>>
>> class WebImage(models.Model):
>>   "Images that are used on the web pages. Limited to certain sizes. Can 
>> be produced by an ImageGenerator."
>>   def get_image_file_path(inst, filename):
>> fn, ext = os.path.splitext(filename)
>> filename = "%s%s" % (uuid.uuid4(), ext)
>> return os.path.join(settings.MEDIA_ROOT+'wi/', filename)
>>   
>>   name = models.CharField(max_length=80,help_text="Full name of the web 
>> image")
>>   slug = models.SlugField(max_length=50,help_text="Slug for the web image 
>> name")
>>   description = models.TextField(help_text="Image description")
>>   img = 
>> models.ImageField(null=True,upload_to=get_image_file_path,height_field="height",width_field="width")
>>   img_gen = models.ForeignKey('ImageGenerator', blank=True, null=True, 
>> on_delete=models.SET_NULL)
>>   img_size = models.ForeignKey('ImageSize', blank=True, null=True, 
>> default=None, on_delete=models.SET_NULL)
>>   width = models.IntegerField(editable=False,blank=True,help_text="Width 
>> of the picture. Not editable")
>>   height = 
>> models.IntegerField(editable=False,blank=True,help_text="Height of the 
>> picture. Not editable")
>>   licensing = models.TextField(blank=True,help_text="Details of image 
>> ownership, copyright and licensing. Blank for 'same as original image'")
>>   created_by = models.CharField(editable=False,blank=True,max_length=80, 
>> help_text="Uploader. Not editable")
>>   creation_date = 
>> models.DateTimeField(editable=False,blank=True,auto_now_add=True, 
>> help_text="Date/time uploaded. Not editable")
>>   uploaded_by = models.CharField(editable=False,blank=True,max_length=80, 
>> help_text="Uploader. Not editable")
>>   upload_date = 
>> models.DateTimeField(editable=False,blank=True,auto_now_add=True, 
>> help_text="Date/time uploaded. Not editable")
>>   tags = TaggableManager()
>>
>>   def thumb_path(self):
>> return os.path.join(settings.MEDIA_ROOT+'thumb/',os.path.basename(
>> self.img.name))
>>
>>   def thumb_url(self):
>> return "%sthumb/%s" % (settings.MEDIA_URL,os.path.basename(
>> self.img.name))
>>
>>   def create_thumb(self):
>> args = [_CONVERT_CMD, self.img.name] + _CONVERT_THUMBNAIL_OPTS + 
>> [self.thumb_path()]
>> try:
>>   output = subprocess.call(args)
>> except subprocess.CalledProcessError, e:
>>   self.description = "%s\n%s\n%d" % (self.description, e.output, 
>> e.returncode) 
>>   pass # This needs to be a logger.
>> self.save()
>>
>>   def thumb_field(self):
>> return ('' % self.thumb_url())
>>   thumb_field.short_description = "Thumbnail"
>>   thumb_field.allow_tags = True
>>
>>   def get_absolute_url(self):
>> return "%swi/%s" % (settings.MEDIA_URL,os.path.split(self.img.name
>> )[1])
>>
>>   def __unicode__(self):
>> return "%s (%dx%d)" % (self.name,self.width,self.height)
>>
>> 
>> # admin.py
>>
>> class WebImageAdmin(ModelAdmin):
>>   def save_model(self, req, obj, form, change):
>> # Add the uploader info to the object
>> if not change or obj.uploaded_by == '':
>>   obj.uploaded_by = "%s (%s %s)" % (req.user.username, 
>> req.user.first_name, req.user.last_name)
>> # And the creator info in the same manner
>> if not change or obj.created_by == '':
>>   obj.created_by = "%s (%s %s)" % (req.user.username, 
>> req.user.first_name, req.user.last_name)
>>

Re: migrate and runserver commands hang, there is no traceback, no clue yet why (1.7.1)

2014-10-25 Thread JJ Zolper
Carl,

Thanks for responding and giving your input. I just made sure there were no 
other terminals with any sort of connection open. At times I have pgAdmin 
III open but that is currently closed and I ran migrate and same thing it 
hangs. The only other terminals I have are one terminal sitting after the 
server is closed down for my other project and another that has a live 
email server open in python.

jjs-macbook-pro:~ JJZ$ python -m smtpd -n -c DebuggingServer localhost:1025

which I don't think would cause an issue and just to check I used control c 
to close it down and tried to migrate but again it hangs there.

As you can see so far I'm in a pretty big bind, I wish I had any sort of 
lead on this issue. Feel free to ask me for any other code etc or do any 
sort of method or operation to hopefully shed more light on this. 

Thanks a lot,

JJ



On Saturday, October 25, 2014 5:15:04 PM UTC-4, Carl Meyer wrote:
>
> Hi JJ,
>
> One thing that can cause hangs when running migrations is having another 
> process (say a ‘manage.py shell’) with a connection to the same database 
> sitting open, possibly with a transaction in progress that is holding locks 
> on the tables the migrations need to touch. Any possibility that’s what 
> happened here?
>
> Carl
>
> On Oct 25, 2014, at 2:23 PM, JJ Zolper > 
> wrote:
>
> I really wish I could give some useful information in the terms of a 
> traceback so others may have an idea what is happening to me but I'm 
> completely serious when I say I don't even get a traceback right now. Here 
> is the break down of what I did to give an idea of how I ended up at this 
> point, hopefully. I will continue to try to iterate upon this discussion as 
> well through observations to try to work on my own or with others to get 
> down to the cause of the issue.
>
> First with a clean and empty database I ran the migrate command and 
> everything went fine. There were no issues as it ran through:
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py migrate
>
> *Operations to perform:*
>
> *  Synchronize unmigrated apps: *colleges, ads, debug_toolbar, comments, 
> communities, main, athletes, ad_manager
>
> *  Apply all migrations: *admin, contenttypes, sites, auth, sessions
>
> *Synchronizing apps without migrations:*
>
>   Creating tables...
>
> Creating table athletes_athlete_athletecolleges
>
> Creating table athletes_athlete_athletecommunities
>
> Creating table athletes_athlete
>
> Creating table athletes_registrationprofile
>
> Creating table colleges_college
>
> Creating table colleges_collegeevent_attendees
>
> Creating table colleges_collegeevent
>
> Creating table communities_community
>
> Creating table communities_country
>
> Creating table communities_city
>
> Creating table communities_communitypost_city
>
> Creating table communities_communitypost_country
>
> Creating table communities_communitypost
>
> Creating table comments
>
> Creating table comment_flags
>
> Creating table main_teammember
>
> Creating table ads_partner
>
> Creating table ads_ad
>
> Creating table ad_manager_target
>
> Creating table ad_manager_adgroup
>
> Creating table ad_manager_ad
>
> Creating table ad_manager_pagetype
>
> Creating table ad_manager_adtype
>
> Creating table ad_manager_tagtype
>
>   Installing custom SQL...
>
>   Installing indexes...
>
> *Running migrations:*
>
>   Applying contenttypes.0001_initial...* OK*
>
>   Applying auth.0001_initial...* OK*
>
>   Applying admin.0001_initial...* OK*
>
>   Applying sessions.0001_initial...* OK*
>
>   Applying sites.0001_initial...* OK*
>
>
> Next up I called to create a super user and that went fine as well:
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> createsuperuser
>
> Username (leave blank to use 'jjz'): 
>
> Email address: 
>
> Password: 
>
> Password (again): 
>
> Superuser created successfully.
>
>
> Then I ran the makemigrations command for the respective apps and their 
> models that I wanted to have:
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations colleges
>
> *Migrations for 'colleges':*
>
>   *0001_initial.py*:
>
> - Create model College
>
> - Create model CollegeEvent
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations ads
>
> *Migrations for 'ads':*
>
>   *0001_initial.py*:
>
> - Create model Ad
>
> - Create model Partner
>
> - Add field partner to ad
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations comments
>
> *Migrations for 'comments':*
>
>   *0001_initial.py*:
>
> - Create model Comment
>
> - Create model CommentFlag
>
> - Alter unique_together for commentflag (1 constraint(s))
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py 
> makemigrations communities
>
> *Migrations for 'communities':*
>
>   *0001_initial.py*:
>
>

Decimal value allowed for auto primary key

2014-10-25 Thread Kafex
If I have the following model...
class FruitType(models.Model):
  name = models.CharField(max_length=255)

And I insert some records...
FruitType.objects.create(name="Apple")
FruitType.objects.create(name="Orange")

Why is this valid?
FruitType.objects.get(id=1.2) # Gets me the apple
FruitType.objects.get(id=2.9) # Gets me the apple


Django seems to truncate the id to just the integer part.
This also applies to form validation:
class FruitForm(forms.Form):
  type = forms.ModelChoiceField(queryset=FruitType.objects.all())

form = FruitForm(data={'type': 1.5})
form.is_valid() # returns True

Is there any way to prevent this? I.e., I want my form to treat 1.5 as 
invalid input and raise a ValidationError.

Thank you.


-- 
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/9f495b17-6f48-485b-9a6a-75f9e83f59b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Integer Form with Select Widget?

2014-10-25 Thread Farhan Khan
Any takers? I suspect that I need to mess around with the form during 
instantiation, but not sure how.

On Saturday, October 25, 2014 12:29:45 PM UTC-4, Farhan Khan wrote:
>
> Hi all,
>
> I want to get an Integer value from the user through a forms.Form. I have 
> three unique requirements for it.
>
>1. The corresponding Widget is Select or SelectMultiple (either one)
>2. The 'choices' field is dynamic, not static or hard-coded -they are 
>adjusted upon each display of the Form based on program logic.
>3. I want the max_value and min_value of IntegerField to also be 
>dynamic - also adjusted based on program logic.
>
>
> What I have thus far is this:
>
> class deleteUserForm(forms.Form):
>delUserId = forms.CharField(label='delUserId', widget=forms.Select)
>
> How would this work?
>
> Thanks
> - Farhan
>

-- 
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/db7e9e3e-3cf2-4506-b5a4-d05f018aced8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Decimal value allowed for auto primary key

2014-10-25 Thread Kafex
Whoops... just to clarify...

FruitType.objects.get(id=2.9) # Gets me the apple

I meant to comment that this gets me the orange.


On Saturday, October 25, 2014 8:37:55 PM UTC-4, Kafex wrote:
>
> If I have the following model...
> class FruitType(models.Model):
>   name = models.CharField(max_length=255)
>
> And I insert some records...
> FruitType.objects.create(name="Apple")
> FruitType.objects.create(name="Orange")
>
> Why is this valid?
> FruitType.objects.get(id=1.2) # Gets me the apple
> FruitType.objects.get(id=2.9) # Gets me the apple
>
>
> Django seems to truncate the id to just the integer part.
> This also applies to form validation:
> class FruitForm(forms.Form):
>   type = forms.ModelChoiceField(queryset=FruitType.objects.all())
>
> form = FruitForm(data={'type': 1.5})
> form.is_valid() # returns True
>
> Is there any way to prevent this? I.e., I want my form to treat 1.5 as 
> invalid input and raise a ValidationError.
>
> Thank you.
>
>
>

-- 
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/07857da5-7abf-478c-8f17-be1924e63541%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: migrate and runserver commands hang, there is no traceback, no clue yet why (1.7.1)

2014-10-25 Thread JJ Zolper
So I believe I have solved my issue. It has to do with the inexperience I 
still have with migrations and how certain aspects are approached. I was 
not aware of this issue until now:

https://docs.djangoproject.com/en/1.7/ref/models/fields/#foreignkey

Warning

It is not recommended to have a ForeignKey from an app without migrations 
to an app with migrations. See thedependencies documentation 

 for 
more details.


and thus:


https://docs.djangoproject.com/en/1.7/topics/migrations/#unmigrated-dependencies


So basically as it was shown I made migrations for my user app athletes 
with the model being Athlete, and so when I tried to establish the 
migrations for all my apps with migrate I was basically presenting this 
dependency issue. I should have left athlete unmigrated and create 
migrations for all my other apps. It is the nature of the FK and I didn't 
catch onto it. There is no output as was stated before, which I'm not sure 
if that is possible in the code but if so I think it could be nice to tell 
people what is going on if at all possible. Tell them that if they have 
some apps with a FK to a model in another app that that other app cannot 
have migrations.


I still have a lot to learn with migrations, but for the time being things 
are operational again.


As time goes on, more and more third-party apps will get migrations, but in 
the meantime you can either give them migrations yourself (using 
MIGRATION_MODULES 

 to 
store those modules outside of the app’s own module if you wish), or keep 
the app with your user model unmigrated.


Maybe in the future I won't have to even think about this if improvements 
are made to this situation. I might follow option 1 with giving it 
migrations outside the app's own module, but for the time being my quick 
fix is leaving my athlete app unmigrated, whereas everything else is.


JJ



On Saturday, October 25, 2014 5:15:04 PM UTC-4, Carl Meyer wrote:
>
> Hi JJ,
>
> One thing that can cause hangs when running migrations is having another 
> process (say a ‘manage.py shell’) with a connection to the same database 
> sitting open, possibly with a transaction in progress that is holding locks 
> on the tables the migrations need to touch. Any possibility that’s what 
> happened here?
>
> Carl
>
> On Oct 25, 2014, at 2:23 PM, JJ Zolper > 
> wrote:
>
> I really wish I could give some useful information in the terms of a 
> traceback so others may have an idea what is happening to me but I'm 
> completely serious when I say I don't even get a traceback right now. Here 
> is the break down of what I did to give an idea of how I ended up at this 
> point, hopefully. I will continue to try to iterate upon this discussion as 
> well through observations to try to work on my own or with others to get 
> down to the cause of the issue.
>
> First with a clean and empty database I ran the migrate command and 
> everything went fine. There were no issues as it ran through:
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.py migrate
>
> *Operations to perform:*
>
> *  Synchronize unmigrated apps: *colleges, ads, debug_toolbar, comments, 
> communities, main, athletes, ad_manager
>
> *  Apply all migrations: *admin, contenttypes, sites, auth, sessions
>
> *Synchronizing apps without migrations:*
>
>   Creating tables...
>
> Creating table athletes_athlete_athletecolleges
>
> Creating table athletes_athlete_athletecommunities
>
> Creating table athletes_athlete
>
> Creating table athletes_registrationprofile
>
> Creating table colleges_college
>
> Creating table colleges_collegeevent_attendees
>
> Creating table colleges_collegeevent
>
> Creating table communities_community
>
> Creating table communities_country
>
> Creating table communities_city
>
> Creating table communities_communitypost_city
>
> Creating table communities_communitypost_country
>
> Creating table communities_communitypost
>
> Creating table comments
>
> Creating table comment_flags
>
> Creating table main_teammember
>
> Creating table ads_partner
>
> Creating table ads_ad
>
> Creating table ad_manager_target
>
> Creating table ad_manager_adgroup
>
> Creating table ad_manager_ad
>
> Creating table ad_manager_pagetype
>
> Creating table ad_manager_adtype
>
> Creating table ad_manager_tagtype
>
>   Installing custom SQL...
>
>   Installing indexes...
>
> *Running migrations:*
>
>   Applying contenttypes.0001_initial...* OK*
>
>   Applying auth.0001_initial...* OK*
>
>   Applying admin.0001_initial...* OK*
>
>   Applying sessions.0001_initial...* OK*
>
>   Applying sites.0001_initial...* OK*
>
>
> Next up I called to create a super user and that went fine as well:
>
> (zcosystem)jjs-macbook-pro:athletesunited JJZ$ python manage.p

REST Framework, choices fields

2014-10-25 Thread Lachlan Musicman
When using GET to retrieve data, how do I populate the JSON with
get_FOO_display rather than FOO?

cheers
L.

-- 
You have to be really clever to come up with a genuinely dangerous
thought. I am disheartened that people can be clever enough to do that
and not clever enough to do the obvious thing and KEEP THEIR IDIOT
MOUTHS SHUT about it, because it is much more important to sound
intelligent when talking to your friends.
This post was STUPID.
---
The Most Terrifying Thought Experiment of All Time
http://www.slate.com/articles/technology/bitwise/2014/07/roko_s_basilisk_the_most_terrifying_thought_experiment_of_all_time.html

-- 
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/CAGBeqiPDZOpOQ8%3D1SGK6WkOKpDx%2BJbNgZBZJZ0rHP1U56g34LQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: REST Framework, choices fields

2014-10-25 Thread Lachlan Musicman
 Done.

long_type = serializers.CharField(source='get_FOO_display')

On 26 October 2014 14:38, Lachlan Musicman  wrote:
> When using GET to retrieve data, how do I populate the JSON with
> get_FOO_display rather than FOO?
>
> cheers
> L.
>
> --
> You have to be really clever to come up with a genuinely dangerous
> thought. I am disheartened that people can be clever enough to do that
> and not clever enough to do the obvious thing and KEEP THEIR IDIOT
> MOUTHS SHUT about it, because it is much more important to sound
> intelligent when talking to your friends.
> This post was STUPID.
> ---
> The Most Terrifying Thought Experiment of All Time
> http://www.slate.com/articles/technology/bitwise/2014/07/roko_s_basilisk_the_most_terrifying_thought_experiment_of_all_time.html



-- 
You have to be really clever to come up with a genuinely dangerous
thought. I am disheartened that people can be clever enough to do that
and not clever enough to do the obvious thing and KEEP THEIR IDIOT
MOUTHS SHUT about it, because it is much more important to sound
intelligent when talking to your friends.
This post was STUPID.
---
The Most Terrifying Thought Experiment of All Time
http://www.slate.com/articles/technology/bitwise/2014/07/roko_s_basilisk_the_most_terrifying_thought_experiment_of_all_time.html

-- 
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/CAGBeqiNxPnEUr7uvNx7HJ7ER8p8nX0%2BwmiwpKD27SjZCb31FkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.