ModelAdmin.save_as integrity error

2015-06-22 Thread Mike Dewhirst

The following is all I could find in the docs about ModelAdmin.save_as

ModelAdmin.save_as 
(https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_as)


Set save_as to enable a “save as” feature on admin change forms.

Normally, objects have three save options: “Save”, “Save and 
continue editing” and “Save and add another”. If save_as is True, “Save 
and add another” will be replaced by a “Save as” button.


“Save as” means the object will be saved as a new object (with a 
new ID), rather than the old object.


By default, save_as is set to False.



I'm having problems with [save as new] when the model has inlines. Is 
there a known gotcha in this area?


The particular error I'm seeing is ...



IntegrityError at /admin/substance/substance/20/

duplicate key value violates unique constraint 
"substance_liquid_substance_id_key"

DETAIL:  Key (substance_id)=(54) already exists.

Request Method: POST
Request URL:http://localhost:8000/admin/substance/substance/20/
Django Version: 1.7.8
Exception Type: IntegrityError
Exception Value:

duplicate key value violates unique constraint 
"substance_liquid_substance_id_key"

DETAIL:  Key (substance_id)=(54) already exists.

Exception Location: 
C:\Users\mike\env\xxex3\lib\site-packages\django\db\backends\utils.py in 
execute, line 65

Python Executable:  C:\Users\mike\env\xxex3\Scripts\python.exe
Python Version: 3.4.3
Python Path:

['/var/www/ssds',
 'C:\\Users\\mike\\env\\xxex3\\ssds',

'C:\\Users\\mike\\env\\xxex3\\lib\\site-packages\\psycopg2-2.5.4-py3.4-win32.egg',

'C:\\Users\\mike\\env\\xxex3\\lib\\site-packages\\pillow-2.7.0-py3.4-win32.egg',
 'C:\\WINDOWS\\SYSTEM32\\python34.zip',
 'C:\\Users\\mike\\env\\xxex3\\DLLs',
 'C:\\Users\\mike\\env\\xxex3\\lib',
 'C:\\Users\\mike\\env\\xxex3\\Scripts',
 'C:\\Python34\\Lib',
 'C:\\Python34\\DLLs',
 'C:\\Users\\mike\\env\\xxex3',
 'C:\\Users\\mike\\env\\xxex3\\lib\\site-packages',
 'C:/Users/mike/env/xxex3/ssds']

Server time:Tue, 23 Jun 2015 12:08:44 +1000


The relationship between substance and liquid is 1:1 and the error is 
highlighted in my liquid.save() method. However, when I comment that 
whole save() method out and try [save as new] again the error doesn't 
change, just the substance pk which increments from 54 (as above) to 55 
and none of my code seems to be involved. Or at least the traceback 
doesn't highlight any.


There appear to be no problems with the code saving normally and there 
are hundreds of unit tests all passing successfully.


I would really appreciate any help. Is there more info I can provide?

Python 3.4 (Windows 8.1)
Django 1.7.8 (Windows 8.1)
Postgres 9.1 (Ubuntu 12.04)

Thanks for any hints.

Mike

--
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/5588CAFF.3070807%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: The related_name of ForeignKey cannot be Unicode name after Django 1.8

2015-06-22 Thread Cheng-Hung Hsueh
I have posted in https://code.djangoproject.com/ticket/25016#ticket .

Tim Graham於 2015年6月23日星期二 UTC+8上午12時30分48秒寫道:
>
> It looks like the check added in ticket #22064 may be too strict (only 
> allowing alphanumeric characters in related_name). Would you like to open a 
> ticket?
>
> On Monday, June 22, 2015 at 11:28:50 AM UTC-4, Cheng-Hung Hsueh wrote:
>>
>> This code can run before django 1.7
>> But "related_name" got an error after django 1.8
>>
>> 使用者表.來源: (fields.E306) The name '使用者' is invalid related_name for field 
>> 使用者表.來源
>>
>>
>> class 來源表(models.Model):
>> 名 = models.CharField(max_length=100)
>>
>> class 使用者表(models.Model):
>> 來源 = models.OneToOneField(來源表, related_name='使用者', primary_key=True, 
>> null=False)
>>
>>
>> Is it a bug? I know adding many checks in Django 1.8
>>
>

-- 
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/1b762fd2-3fea-480b-9d60-535adafb4209%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "RuntimeError: Error creating new content types."

2015-06-22 Thread Devang Mundhra
Chris-
By any chance, did you fake any of the migrations. That was the problem I
had faced- it wasn't a Django problem, it was a problem with my migration.

On Mon, Jun 22, 2015 at 3:52 PM Chris DiLorenzo <
dilorenzo.christop...@gmail.com> wrote:

> I'm seeing this issue as well. Not sure if it helps but I get it when
> running my tests.
>
> I chose to raise the error instead and saw this:
>
> django.db.utils.IntegrityError: null value in column "name" violates not-
> null
> constraint
> DETAIL:  Failing row contains (1, null, app, listing).
>
>
> Where app is the django app name and listing is the model name. So that
> sounds to me like I'm seeing what everyone else is, the migration is just
> not applied on the database for some reason, but shows as being applied OK.
>
> // Chris
>
>
> On Wednesday, June 10, 2015 at 11:31:42 AM UTC-4, Devang Mundhra wrote:
>
>> In my case this is not a Django bug.
>> The problem was that since 1.8 contenttypes started to have migrations.
>> But since the table already existed earlier, the migrations needed to be
>> faked.
>> When faking the migrations, I used python manage.py migrate contenttypes
>> --fake which faked both 0001 and 0002.
>>
>> The fix was to remove the fake migration for 0002 from django_migrations
>> table and then do the actual migration.
>>
>> On Wed, Jun 10, 2015 at 6:57 AM Tim Graham  wrote:
>>
> If anyone running into this problem can figure out why the
>>> contrib.contenttypes migration (0002_remove_content_type_name) is being
>>> marked as applied but not actually run in the database, that will help
>>> determine if this is a bug in Django or a problem elsewhere.
>>>
>>>
>>> On Wednesday, June 10, 2015 at 7:11:48 AM UTC-4, Devang Mundhra wrote:

 I am getting the same error on Django v1.8.2 after migrating from v1.7.7
 The underlying error is this-

 django.db.utils.IntegrityError: null value in column "name" violates
> not-null constraint
> DETAIL:  Failing row contains (39, null, app_name, model_name).
>
>
 On Friday, April 17, 2015 at 1:25:06 PM UTC-7, Tim Graham wrote:
>
> The contenttypes name column was removed in Django 1.8. Could you
> retrieve the underlying exception before the RuntimeError is raised?
>
> On Friday, April 17, 2015 at 2:55:07 PM UTC-4, Christophe Pettus wrote:
>>
>> Digging into this a bit more, the specific exception is that it is
>> trying to insert a contenttypes row with a null 'name' value.
>>
>> The code in question is doing a get_or_create() on the contenttype
>> object.  I assume it should be picking up the name from the name 
>> @property
>> on the ContentType model, but I don't see that ever actually being 
>> called.
>>
>>
>> On Apr 17, 2015, at 11:24 AM, Christophe Pettus 
>> wrote:
>>
>> > On Django 1.8, I'm encountering this error when attempting to apply
>> migrations on the production system.  What's interesting is that it works
>> fine on the dev system, and inspecting the django_migrations table, I 
>> don't
>> see any (meaningful) differences between them (error text below).
>> >
>> > There was a model added to the "catalog" application which is not
>> being created in django_content_type.
>> >
>> > Manually migrating contenttypes individually generates the same
>> error.
>> >
>> > --
>> >
>> > $ python manage.py migrate
>> > Operations to perform:
>> >  Synchronize unmigrated apps: staticfiles, util, treebeard,
>> messages, office
>> >  Apply all migrations: info, customers, sessions, admin,
>> contenttypes, auth, sites, catalog, coming_soon, orders
>> > Synchronizing apps without migrations:
>> >  Creating tables...
>> >Running deferred SQL...
>> >  Installing custom SQL...
>> > Running migrations:
>> >  Rendering model states... DONE
>> >  Applying auth.0006_require_contenttypes_0002... OK
>> > Traceback (most recent call last):
>> >  File "manage.py", line 10, in 
>> >execute_from_command_line(sys.argv)
>> >  File
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>> line 338, in execute_from_command_line
>> >utility.execute()
>> >  File
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>> line 330, in execute
>> >self.fetch_command(subcommand).run_from_argv(self.argv)
>> >  File
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>> line 390, in run_from_argv
>> >self.execute(*args, **cmd_options)
>> >  File
>> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>> line 441, in execute
>> >output = self.handle(*args, **options)
>> >  File

Re: "RuntimeError: Error creating new content types."

2015-06-22 Thread Chris DiLorenzo
I'm seeing this issue as well. Not sure if it helps but I get it when 
running my tests.

I chose to raise the error instead and saw this:

django.db.utils.IntegrityError: null value in column "name" violates not-
null constraint
DETAIL:  Failing row contains (1, null, app, listing).


Where app is the django app name and listing is the model name. So that 
sounds to me like I'm seeing what everyone else is, the migration is just 
not applied on the database for some reason, but shows as being applied OK.

// Chris


On Wednesday, June 10, 2015 at 11:31:42 AM UTC-4, Devang Mundhra wrote:
>
> In my case this is not a Django bug.
> The problem was that since 1.8 contenttypes started to have migrations. 
> But since the table already existed earlier, the migrations needed to be 
> faked.
> When faking the migrations, I used python manage.py migrate contenttypes 
> --fake which faked both 0001 and 0002.
>
> The fix was to remove the fake migration for 0002 from django_migrations 
> table and then do the actual migration.
>
> On Wed, Jun 10, 2015 at 6:57 AM Tim Graham  > wrote:
>
>> If anyone running into this problem can figure out why the 
>> contrib.contenttypes migration (0002_remove_content_type_name) is being 
>> marked as applied but not actually run in the database, that will help 
>> determine if this is a bug in Django or a problem elsewhere.
>>
>>
>> On Wednesday, June 10, 2015 at 7:11:48 AM UTC-4, Devang Mundhra wrote:
>>>
>>> I am getting the same error on Django v1.8.2 after migrating from v1.7.7
>>> The underlying error is this-
>>>
>>> django.db.utils.IntegrityError: null value in column "name" violates not
 -null constraint
 DETAIL:  Failing row contains (39, null, app_name, model_name).


>>> On Friday, April 17, 2015 at 1:25:06 PM UTC-7, Tim Graham wrote:

 The contenttypes name column was removed in Django 1.8. Could you 
 retrieve the underlying exception before the RuntimeError is raised?

 On Friday, April 17, 2015 at 2:55:07 PM UTC-4, Christophe Pettus wrote:
>
> Digging into this a bit more, the specific exception is that it is 
> trying to insert a contenttypes row with a null 'name' value. 
>
> The code in question is doing a get_or_create() on the contenttype 
> object.  I assume it should be picking up the name from the name 
> @property 
> on the ContentType model, but I don't see that ever actually being 
> called. 
>
>
> On Apr 17, 2015, at 11:24 AM, Christophe Pettus  
> wrote: 
>
> > On Django 1.8, I'm encountering this error when attempting to apply 
> migrations on the production system.  What's interesting is that it works 
> fine on the dev system, and inspecting the django_migrations table, I 
> don't 
> see any (meaningful) differences between them (error text below). 
> > 
> > There was a model added to the "catalog" application which is not 
> being created in django_content_type. 
> > 
> > Manually migrating contenttypes individually generates the same 
> error. 
> > 
> > -- 
> > 
> > $ python manage.py migrate 
> > Operations to perform: 
> >  Synchronize unmigrated apps: staticfiles, util, treebeard, 
> messages, office 
> >  Apply all migrations: info, customers, sessions, admin, 
> contenttypes, auth, sites, catalog, coming_soon, orders 
> > Synchronizing apps without migrations: 
> >  Creating tables... 
> >Running deferred SQL... 
> >  Installing custom SQL... 
> > Running migrations: 
> >  Rendering model states... DONE 
> >  Applying auth.0006_require_contenttypes_0002... OK 
> > Traceback (most recent call last): 
> >  File "manage.py", line 10, in  
> >execute_from_command_line(sys.argv) 
> >  File 
> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>  
> line 338, in execute_from_command_line 
> >utility.execute() 
> >  File 
> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>  
> line 330, in execute 
> >self.fetch_command(subcommand).run_from_argv(self.argv) 
> >  File 
> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>  
> line 390, in run_from_argv 
> >self.execute(*args, **cmd_options) 
> >  File 
> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/base.py",
>  
> line 441, in execute 
> >output = self.handle(*args, **options) 
> >  File 
> "/home/tbc/environments/fugu/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
>  
> line 225, in handle 
> >emit_post_migrate_signal(created_models, self.verbosity, 
> self.interactive, connection.alias) 
> >  File 

Manually add image to filefield in save method on modelform

2015-06-22 Thread Andreas Kuhne
Hi all,

I have created a modelform that has an Imagefield in it. I want to override
the save function and manually create a filefield with an image that
already exists in the file storage (S3). So the things I have to do would
be:

* Download the image from S3 and save it to a temporary file
* Create a TemporaryUploadedFile and add it the the cleaned_data dictionary.
* Continue with the save method.

This should upload the file again and then connect the file to the model.

Has anyone done this before and could point me in the correct direction on
howto create the TemporaryUploadedFile object?

Regards,

Andréas

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


HStore values query with contains not working as expected

2015-06-22 Thread Alex Magidow
Hi,

I was going to file this as a bug, but it said to ask the mailing list 
first. 

When using an HStore __values query with __contains chained on to it, the 
query does not work as expected in Django 1.8.2. Expected action is that 
any values which contain the text will be returned from the query.

>From my own app (I've removed some of the queryset results to make this 
easier to read)

>>> query1
[, , , '...(remaining elements 
truncated)...']
>>> query1.filter(multigloss__values__contains=["This"])
[]
>>> query1.filter(multigloss__values__contains=["This (f)"])
[,  , '...(remaining elements truncated)...']
>>> query1.filter(multigloss__values__contains=["His"])
[, , 
,  
'...(remaining elements truncated)...']
>>> query1.filter(multigloss__values__contains=["Hi"])
[]

The expected result would be that the queries would return any data whose 
'multigloss' values contain the string, not only those strings which are 
exactly identical. 

The example in the documentation should also fail if you did not include 
the entire word "collie" (I have not tested, this is a hypothesized result):

>>> Dog.objects.create(name='Rufus', data={'breed': 'labrador'})
>>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': 'Bob'})

>>> Dog.objects.filter(data__values__contains=['collie'])
[]

>>>#Hypothesized example!
>>> Dog.objects.filter(data__values__contains=['coll'])
[]
>>>#Should have returned [Dog: Meg]

Is there a way to do the query that I'm trying to do here, or have I found 
a bug? 

Thanks,
Alex

-- 
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/4137b90b-4c51-49e8-a05d-181626baac8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Queryset Practice

2015-06-22 Thread Luis Zárate
Querysets are lazy,  so Model.objects.all().filter(...) execute a same
query that Model.objects.filter(...).all()  and Model.objects.filter(...).
For check this tray  in shell

str(Model.objects.all().filter(pk=1).query)

str(Model.objects.filter(pk=1).all().query)

str(Model.objects.filter(pk=1).query)


2015-06-22 10:32 GMT-06:00 Tim Graham :

> Have you had a look at the documentation?
>
> https://docs.djangoproject.com/en/stable/topics/db/optimization/#understand-querysets
>
> On Monday, June 22, 2015 at 11:28:51 AM UTC-4, Paritosh Gupta wrote:
>>
>> Hello,
>>
>> Do advice me on:
>>
>> queryset = User.objects.all()
>> user = get_object_or_404(pk=id)
>>
>>
>>
>> > Is it better to call the list in queryset and then apply filter or
>> directly use .filter() in the first step.
>>
>> > If so, when we call all the object frequently does it cache and from
>> cache we do filter or does it db everytime.
>>
>  --
> 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/6879eaf6-d906-40ff-8ff1-bed514621856%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

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


conflicts with six.moves

2015-06-22 Thread Christopher L. Trudeau
I've been using django to interface with a couple of data source libraries,
both of which use six. There appears to be some sort of conflict problem
between six and django.utils.six which causes ImportErrors.

For example, using the Reddit library "praw":

> from six.moves.urllib.parse import parse_qs, urlparse, urlunparse

ImportError: No module named urllib.parse

or from Google-API:

>>> from apiclient.discovery import build

from six.moves import urllib

ImportError: cannot import name urllib

When looking around the web for problems with six, the common answer is to
change the order of the import so that the more recent copy is first,
obviously I can't do that if things are wrapped inside of django.  I have
tried six v1.4, 1.8 and 1.9, none of which work.

I have tried explicitly removing django.utils.six's _SixMetaPathImporter
from sys.meta_path before doing the imports and it still fails.  In
debugging I have found that anything in six that is a MovedModule will fail
to import but those things that are MovedAttribute objects still work.

I have django installed in a virtualenv.  I have tried this with Django
1.7.5 and 1.8.2 with no luck.  If I run the import commands from the python
interpreter directly they work, but if I run the same import command from
"./manage.py shell" the import fails.

In playing around I instrumented the non-django copy of six and was able to
get it to list all of its module values including those it can't import.
So on one hand the module thinks it is there, but the import hook fails.

I'm not even 100% sure this is a django problem and not a conflict with
some other library in the virtualenv, I do know that something that
"manage.py" brings into the path is causing issues.  Any help would be
greatly appreciated.  My head is sore from banging against this particular
wall.
...ct

-- 
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/CANk-4bi7S5GPPpZNNLGY%3DzFge4u_2cL4R7eGdK8h2pVx5gHbpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Queryset Practice

2015-06-22 Thread Tim Graham
Have you had a look at the documentation?
https://docs.djangoproject.com/en/stable/topics/db/optimization/#understand-querysets

On Monday, June 22, 2015 at 11:28:51 AM UTC-4, Paritosh Gupta wrote:
>
> Hello,
>
> Do advice me on:
>
> queryset = User.objects.all()
> user = get_object_or_404(pk=id)
>
>
>
> > Is it better to call the list in queryset and then apply filter or 
> directly use .filter() in the first step.
>
> > If so, when we call all the object frequently does it cache and from 
> cache we do filter or does it db everytime.
>

-- 
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/6879eaf6-d906-40ff-8ff1-bed514621856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: The related_name of ForeignKey cannot be Unicode name after Django 1.8

2015-06-22 Thread Tim Graham
It looks like the check added in ticket #22064 may be too strict (only 
allowing alphanumeric characters in related_name). Would you like to open a 
ticket?

On Monday, June 22, 2015 at 11:28:50 AM UTC-4, Cheng-Hung Hsueh wrote:
>
> This code can run before django 1.7
> But "related_name" got an error after django 1.8
>
> 使用者表.來源: (fields.E306) The name '使用者' is invalid related_name for field 
> 使用者表.來源
>
>
> class 來源表(models.Model):
> 名 = models.CharField(max_length=100)
>
> class 使用者表(models.Model):
> 來源 = models.OneToOneField(來源表, related_name='使用者', primary_key=True, 
> null=False)
>
>
> Is it a bug? I know adding many checks in Django 1.8
>

-- 
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/279ee276-297d-4b40-afe3-917167ffaf44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Best Queryset Practice

2015-06-22 Thread Paritosh Gupta
Hello,

Do advice me on:

queryset = User.objects.all()
user = get_object_or_404(pk=id)



> Is it better to call the list in queryset and then apply filter or 
directly use .filter() in the first step.

> If so, when we call all the object frequently does it cache and from 
cache we do filter or does it db everytime.

-- 
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/0d1de3cd-af5b-4fb5-b4df-5efe114f9e4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


The related_name of ForeignKey cannot be Unicode name after Django 1.8

2015-06-22 Thread Cheng-Hung Hsueh
This code can run before django 1.7
But "related_name" got an error after django 1.8

使用者表.來源: (fields.E306) The name '使用者' is invalid related_name for field 
使用者表.來源


class 來源表(models.Model):
名 = models.CharField(max_length=100)

class 使用者表(models.Model):
來源 = models.OneToOneField(來源表, related_name='使用者', primary_key=True, 
null=False)


Is it a bug? I know adding many checks in Django 1.8

-- 
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/453092fc-deca-422b-a405-e32ad3b41b1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: No JSON object could be decoded

2015-06-22 Thread Bill Freeman
You probably don't want request.body.  You are probably POSTing the JSON
using a form, which means that it shows up as something like
request.POST['data'], where you should replace 'data' with the name of the
form element (textarea?) where you are putting the JSON.  Posting with a
form wraps things up in a multipart form (allowing you to have, among other
things, more than one field in a post), and that extra stuff doesn't look
line JSON, but the whole is what you get when you use request.body.

On Sun, Jun 21, 2015 at 11:13 AM, Vijay Khemlani  wrote:

> What is the actual content of request.body? (as in, "print request.body")
>
> On Sun, Jun 21, 2015 at 9:26 AM, Dhaval M  wrote:
>
>> Thank you in advance for any help (this is my first post to this
>> community)
>>
>> I am using Django as my application server for my project. I am new to
>> web development so please pardon and feel free to correct me for any
>> mistake.
>>
>> I am running simple, client server combination where from client I am
>> trying to send JSON data and on the server I am trying to parse it.
>>
>> SERVER CODE:
>>
>> def addPatient(request):
>>
>>  if request.method == 'POST':
>>
>> # Convert JSON to python objects and
>>
>> # store into the DB
>>
>> recJSON = json.loads(request.body)
>>
>> #logger.debug("%s",recJSON['SenderID'])
>>
>> logger.debug("%s",request.body)
>>
>>
>> #print 'Raw Json "%s"' % request.body
>>
>> return HttpResponse(json.dumps(request.body),content_type=
>> "application/json")
>>
>>
>>
>>
>> But getting an error at json.loads. ValueError: No JSON object could be
>> decoded
>>
>>
>> Also I would appreciate if any one can direct me to good tutorial on
>> Django (I already read http://www.djangobook.com/)
>>
>>
>> I dont know where and what I am doing wrong. I checked the client side
>> message and it is JSON used http://jsonlint.com/ to validate it is JSON
>> data.
>>
>>
>> Thank you once again.
>>
>> --
>> 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/5bc51870-6b56-456f-bc6d-18cf20487265%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/CALn3ei1Sdb_QGG3hxixj2RNqiqaafjQMkwqGkpokXqcCOGgejA%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/CAB%2BAj0sUoKrU%2BGYBij8hnbMNkggdJFUBsYm9GNvZ%3D3nUc89B0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Passing an image to the other url?

2015-06-22 Thread Jeremi Podlasek
Please beware that I'm just few weeks into django and really do not feel 
confortable at it

In my first django project I've created an app which is uploading images to 
the site, the images are stored at the same link the uploading takes place

What I'm trying to accomplish is to upload the images at the /list.html and 
to display the images on the homepage.
I've tried to inherit template from list.html so the homepage would have 
the variable images so I could iterate over it but to no avail.
I'm stuck and really a django framework beginner.

All the homepage says is "No images."



models.py 
from django.db import models
from PIL import Image

class Image(models.Model):
imgfile = models.ImageField(upload_to='images/%Y/%m/%d')



forms.py
from django import forms

class ImageForm(forms.Form):
imgfile = forms.ImageField(
label='Select a file',
)


views.py
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

from .models import Image
from .forms import ImageForm

def list(request):
# handling the file upload process
if request.method == 'POST':
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
newimg = Image(imgfile = request.FILES['imgfile'])
newimg.save()

# point to the list of images
return HttpResponseRedirect(reverse('img.views.list'))
else:
form = ImageForm() # show nothing

#load images on the list page
images = Image.objects.all()

# render list page with the images & the browse form
return render_to_response(

'img/list.html',
{'images': images, 'form':form},
context_instance=RequestContext(request)
)


and templates: 

list.html
{% extends "site_base.html" %}

{% load i18n %}

{% block head_title %}site for specific people{% endblock %}

{% block body_class %}list{% endblock %}

{% block body_base %}


{% include "_messages.html" %}
{% blocktrans %}Add an image!{% endblocktrans %}

 
  
  {% if images %}

{% for image in images %}
{{ image.imgfile.title }}


{% endfor %}

{% else %}
No images.
{% endif %}





  



{% csrf_token %}
{{ form.non_field_errors }}
{{ form.imgfile.label_tag }} {{ form.image.help_text }}

{{ form.imgfile.errors }}
{{ form.imgfile }}  
   


 



{% endblock %}

homepage.html
{% extends "img/list.html" %}

{% load i18n %}

{% block head_title %}site for specific people{% endblock %}

{% block body_class %}home{% endblock %}

{% block body_base %}


{% include "_messages.html" %}
   
  
{% if not user.is_authenticated %}
{% url "account_login" as login_url %}
{% url "account_signup" as signup_url %}
{% blocktrans %}Feel free to Log In or Sign Up and post an image!{% 
endblocktrans %}
{% endif %}


{% if images %}

{% for image in images %}
{{ image.imgfile.title }}


{% endfor %}

{% else %}
No images.
{% endif %}








  



{% endblock %}



-- 
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/8672dac2-e16b-494c-9a17-6ca0e59422bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.