Image browsing in django

2013-10-10 Thread Harjot Mann
When I am browsing an image in my form it is giving me this error even
after browsing the image. :(
http://screencloud.net/v/ch9e

-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

-- 
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/CAB0GQhB3wbUhVNRSsU%2BL-ksMxY4PgykrDwYuKuw4cfMtGWwPsg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Edited objects in admin interface aren't saved

2013-10-10 Thread Nubrigol
I'm having this weird problem in my admin interface where deleting and 
creating objects works fine, but if I try to edit an object, the changes 
aren't saved.  There are no errors and the save button appears to work, 
until you look back at the object you saved and it doesn't reflect the 
changes at all.  This happens when served with nginx/gunicorn and with the 
manage.py development server.  Debug mode does not provide any extra 
information.

Has anyone seen this before? 

I'm not sure what extra info you might need.


-Nub

-- 
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/caede5d8-fdc1-49f5-9d40-c89118df3306%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Retrieving json stored in TextField as json

2013-10-10 Thread Marc Aymerich
On Thu, Oct 10, 2013 at 6:02 PM, Daniel Roseman  wrote:
> On Thursday, 10 October 2013 10:08:18 UTC+1, Marc Aymerich wrote:
>>
>> Hi Rafael, thanks !
>> I forgot to mention that I was already using django-jsonfield
>> https://github.com/bradjasper/django-jsonfield
>> and now I've tried with django-json-field but with the same unfortunate
>> result:
>>
>> TimeSerie.objects.filter(type='cpu').values('value')
>> [{'value':
>> '{"scheduled":2,"total":864,"15min":0.38,"1min":0.3,"5min":0.48}'},
>> {'value':
>> '{"scheduled":2,"total":859,"15min":0.34,"1min":0.23,"5min":0.32}'},
>> {'value':
>> '{"scheduled":2,"total":849,"15min":0.33,"1min":0.51,"5min":0.32}'}]
>>
>> did I missed something?
>>
>
> You need to show how you are storing this value in the first place.

yep, here we go

class TimeSerie(models.Model):
type = models.CharField(max_length=64)
value = JSONField()
date = models.DateTimeField(auto_now_add=True)


# This is how the value is stored
value = json.loads(run(self.cmd, display=False).stdout)
TimeSerie.objects.create(type=self.name, value=value)


# And this is how it looks like using ValuesQuerySet vs accessing the
object value

>>> TimeSerie.objects.filter(pk=4769).values('value')
[{'value': 
'{"used":5358516,"cached":3191544,"free":2729444,"real-used":2044016,"shared":0,"real-free":6043944,"total":8087960,"buffers":122956}'}]

>>> TimeSerie.objects.filter(pk=4769)[0].values
{u'used': 5358516, u'cached': 3191544, u'free': 2729444, u'real-used':
2044016, u'shared': 0, u'real-free': 6043944, u'total': 8087960,
u'buffers': 122956}

One is an string and the other is a dict.

And here using raw sql
=# select value from monitor_timeserie where id=4769;
value
--
 
{"used":5358516,"cached":3191544,"free":2729444,"real-used":2044016,"shared":0,"real-free":6043944,"total":8087960,"buffers":122956}
(1 row)


it's a json field acctually
=# \d+ monitor_timeserie;
  Table
"public.monitor_timeserie"
 Column |   Type   |
Modifiers| Storage  | Stats target |
Description
+--++--+--+-
 id | integer  | not null default
nextval('monitor_timeserie_id_seq'::regclass) | plain|
 |
 type   | character varying(64)| not null
 | extended |  |
 value  | json | not null
 | extended |  |
 date   | timestamp with time zone | not null
 | plain|  |
Indexes:
"monitor_timeserie_pkey" PRIMARY KEY, btree (id)
"monitor_timeserie_date_4395efb9" btree (date, type)
Has OIDs: no


-- 
Marc

-- 
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/CA%2BDCN_urOzXqLBL6DfeVc3kTHQEz2xXsuiaP1Btr8S-ygAZFbg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Call method of the session template

2013-10-10 Thread Bill Freeman
No.  You can't pass an argument to a model method from the template.  I see
two options for you:

1.  Rework the method so that the argument is optional, and if the argument
is not provided, the method uses a reasonable default (maybe item.product?).
2. Write a custom template filter that lets you supply an argument


On Thu, Oct 10, 2013 at 3:17 PM, Ricardo Kamada wrote:

> I tried numerous times ...
> but if I put that way
> {% 'item.remove_single' item.product %} or {% 'item.remove_single'
> product= item.product %}
> blames this error " Invalid block tag: ''item.remove_single'', expected
> 'empty' ou 'endfor' "
>
> Ricardo
>
>
> 2013/10/10 Bill Freeman 
>
>> The remove method requires an argument.  You're not supplying one (you
>> can't in a template variable reference).
>>
>>
>> On Thu, Oct 10, 2013 at 1:29 PM, Ricardo  wrote:
>>
>>> Hi, I'm using django carton to shopping cart.
>>> I am not able to call the method remove_single in my template. on line 15
>>> I tried several ways but I can not.
>>> If you can help
>>>
>>> carton  ---> http://pastebin.com/X4FtHRZU
>>> template  ---> http://pastebin.com/0AJYFB1x
>>>
>>> thank you
>>> Ricardo
>>>
>>> --
>>> 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/b67afb27-366b-4570-85a6-58900322fa3e%40googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/AzIxhSQpGws/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>>
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAB%2BAj0tPL8y7zBwv8RvaBP29D77dALP84WVv_tbHRd1xELfveg%40mail.gmail.com
>> .
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> 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/CAJTdXTH%2BH0BAqRsnKOpvyX75no01n7aUn7YvLgcOY-_jjVB8Wg%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Call method of the session template

2013-10-10 Thread Ricardo Kamada
I tried numerous times ...
but if I put that way
{% 'item.remove_single' item.product %} or {% 'item.remove_single' product=
item.product %}
blames this error " Invalid block tag: ''item.remove_single'', expected
'empty' ou 'endfor' "

Ricardo


2013/10/10 Bill Freeman 

> The remove method requires an argument.  You're not supplying one (you
> can't in a template variable reference).
>
>
> On Thu, Oct 10, 2013 at 1:29 PM, Ricardo  wrote:
>
>> Hi, I'm using django carton to shopping cart.
>> I am not able to call the method remove_single in my template. on line 15
>> I tried several ways but I can not.
>> If you can help
>>
>> carton  ---> http://pastebin.com/X4FtHRZU
>> template  ---> http://pastebin.com/0AJYFB1x
>>
>> thank you
>> Ricardo
>>
>> --
>> 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/b67afb27-366b-4570-85a6-58900322fa3e%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/AzIxhSQpGws/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB%2BAj0tPL8y7zBwv8RvaBP29D77dALP84WVv_tbHRd1xELfveg%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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/CAJTdXTH%2BH0BAqRsnKOpvyX75no01n7aUn7YvLgcOY-_jjVB8Wg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Call method of the session template

2013-10-10 Thread Bill Freeman
The remove method requires an argument.  You're not supplying one (you
can't in a template variable reference).


On Thu, Oct 10, 2013 at 1:29 PM, Ricardo  wrote:

> Hi, I'm using django carton to shopping cart.
> I am not able to call the method remove_single in my template. on line 15
> I tried several ways but I can not.
> If you can help
>
> carton  ---> http://pastebin.com/X4FtHRZU
> template  ---> http://pastebin.com/0AJYFB1x
>
> thank you
> Ricardo
>
> --
> 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/b67afb27-366b-4570-85a6-58900322fa3e%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: ALLOWED_HOSTS and dynamic dyn site

2013-10-10 Thread Xavier Ordoquy
Hi michael,

I've also noticed a couple of issues with it. Thanks to raven and sentry I 
noticed those requests were missing the hostname in their headers and decided I 
didn't care more.
You might want to use them and see if it's the same for you.

Best regards,
Xavier,
Linovia.

Le 10 oct. 2013 à 18:50, R. Michael Herberger  a 
écrit :

> Hello Django Users,
> 
> I have upgraded to django 1.5 and am getting errors because of the 
> ALLOWED_HOSTS, 
> 
> Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS):
> 
> The HTTP_HOST headers are the current IP address of my server depending on 
> what has been allocated. Even with "*", I am getting the error occassionally. 
> 
> The specifics;
> Ubuntu 12.04 LTS
> Apache 2.2 with mod_wsgi
> An easybox 803a forward requests to the server and updates the dynamic IP 
> service. 
> 
> I do not know if it is advisable but it would be nice to verify  
> ALLOWED_HOSTS with the current IP address? Is it possible to change this 
> function to accomadate  my dynamic IP?
> 
> Any suggestions please let me know.
> 
> Kind regards
> Michael
>  
> 
> -- 
> 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/54dde4d2-7286-4158-bc5d-58fa252f0d0d%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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/EB74B39A-ED25-4E1F-BB7B-D01DBDD8D306%40linovia.com.
For more options, visit https://groups.google.com/groups/opt_out.


Call method of the session template

2013-10-10 Thread Ricardo
Hi, I'm using django carton to shopping cart.
I am not able to call the method remove_single in my template. on line 15
I tried several ways but I can not.
If you can help

carton  ---> http://pastebin.com/X4FtHRZU
template  ---> http://pastebin.com/0AJYFB1x

thank you
Ricardo

-- 
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/b67afb27-366b-4570-85a6-58900322fa3e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Looking for a way to detect changes in database records with low storage footprint

2013-10-10 Thread Tom Evans
On Thu, Oct 10, 2013 at 2:55 PM, DJ-Tom  wrote:
>
> Thanks, but *how* can I create a hash from a database object in Django - is
> there a generic method to iterate over all (or only specific) fields and get
> a hash value?
>

This is not a full solution, but you can select out extra fields (and
then subsequently filter on them) using the .extra() method on
querysets.

Eg, if you were using mysql and wanted a field that was a hash of pk
(id), first_name and last_name fields, then you could do something
like so:

>>> User.objects.filter(id__lt=10).extra(
...   select={'hash': 'MD5(CONCAT(id, first_name,
last_name))'}).values_list('hash')
[('a2147bd4161f55a7ca402d8971b6a45e',),
('663dfc6f51e0ef2c9fa6691527722f20',),
('045dde540781fe013c58c3ebb9383df6',),
('70079b2943da078f437a3678578c78f7',),
('2b997848117758e1844875b1119702bb',),
('2602ecfa423f969614af5b6174c6863e',),
('c9f0f895fb98ab9159f51fd0297e236d',)]

I don't know that this necessarily helps in your aim though. It might
be better to have a custom save method which updates a
"report_fields_modified" timestamp column when fields that affect your
report are modified.

Unfortunately, (IIRC) you cannot easily determine which fields have
been modified without first loading a pristine copy of the object you
are saving from the database, which has obvious performance issues.

Cheers

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/CAFHbX1J3ZcNXFGo8y6g9z8z31kpOFfeat0%3DTgOvP51BKUP9C-A%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


ALLOWED_HOSTS and dynamic dyn site

2013-10-10 Thread R. Michael Herberger
Hello Django Users,

I have upgraded to django 1.5 and am getting errors because of the 
ALLOWED_HOSTS, 

Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS):


The HTTP_HOST headers are the current IP address of my server depending on what 
has been allocated. Even with "*", I am getting the error occassionally. 


The specifics;

Ubuntu 12.04 LTS

Apache 2.2 with mod_wsgi

An easybox 803a forward requests to the server and updates the dynamic IP 
service. 


I do not know if it is advisable but it would be nice to verify  ALLOWED_HOSTS 
with the current IP address? Is it possible to change this function to 
accomadate  my dynamic IP?


Any suggestions please let me know.


Kind regards

Michael

 

-- 
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/54dde4d2-7286-4158-bc5d-58fa252f0d0d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Retrieving json stored in TextField as json

2013-10-10 Thread Daniel Roseman
On Thursday, 10 October 2013 10:08:18 UTC+1, Marc Aymerich wrote:

> Hi Rafael, thanks ! 
> I forgot to mention that I was already using django-jsonfield 
> https://github.com/bradjasper/django-jsonfield 
> and now I've tried with django-json-field but with the same unfortunate 
> result: 
>
> TimeSerie.objects.filter(type='cpu').values('value') 
> [{'value': 
> '{"scheduled":2,"total":864,"15min":0.38,"1min":0.3,"5min":0.48}'}, 
> {'value': 
> '{"scheduled":2,"total":859,"15min":0.34,"1min":0.23,"5min":0.32}'}, 
> {'value': 
> '{"scheduled":2,"total":849,"15min":0.33,"1min":0.51,"5min":0.32}'}] 
>
> did I missed something? 
>
>  
You need to show how you are storing this value in the first place.
--
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/d9e2aef5-54ce-4e5c-a17d-8b67412d200c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Extension to QuerySet.values()

2013-10-10 Thread Arnaud Delobelle


On Thursday, 10 October 2013 15:19:32 UTC+1, Ramiro Morales wrote:
>
>
> On Oct 10, 2013 10:02 AM, "Arnaud Delobelle"  
> wrote:
> >
> > Hi Russ,
> >
> > Thanks for the feedback.  I agree that this could possibly be integrated 
> into the values() method.  I just used a new method in order to minimise 
> interference with our existing code.  I'll read the 'contributing' document 
> then see if I can find a bit of spare time to do this properly!
> >
> FYI IIUC this has been reported in ticket 16735:
>
> https://code.djangoproject.com/ticket/16735
>
 Yes.  The patch also seems to allow using the aliases in e.g. order_by() 
or annotate() clauses, which I hadn't got round to looking at yet.  It is 
marked as needing improvement but looking at the change history I'm not 
sure what needs to be improved.

-- 
Arnaud

-- 
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/a2cbb3b0-e014-46c0-99d5-b71acbeb4aa4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: readonly_fields depending on request

2013-10-10 Thread Roberto López López
Hi,

It was something like that:

def get_form(self, request, obj=None, **kwargs):
if not request.user.groups.filter(name__exact='administration')
and not request.user.is_superuser:
import itertools
self.readonly_fields = itertools.chain(self.readonly_fields,
('is_featured', ))
return super(NewsAdmin, self).get_form(request, obj, **kwargs)

Now I see that this was slightly different than what I did with
get_readonly_fields...

On 10/10/2013 03:00 PM, Timothy W. Cook wrote:
> Can you post the code you tried with get_form()?  It should be the
> solution.
>
>
>
> On Thu, Oct 10, 2013 at 9:45 AM, Roberto López López
> > wrote:
>
> Hi,
>
> In my project I make use of django-admin. I need to have different
> readonly_fields depending on the user is connected, thus
> administrators
> will be able to modify all fields, and other users less fields. Which
> method do I have to override? I have already tried
> ModelAdmin.get_readonly_fields() and ModelAdmin.get_form(). But no
> success.
>
> Any other suggestions?
>
> Thanks!
>
> Roberto
>
>
> --
> 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/5256A163.3000907%40uni.no.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> -- 
> MLHIM VIP Signup: http://goo.gl/22B0U
> 
> Timothy Cook, MSc   +55 21 94711995
> MLHIM http://www.mlhim.org
> Like Us on FB: https://www.facebook.com/mlhim2
> Circle us on G+: http://goo.gl/44EV5
> Google Scholar: http://goo.gl/MMZ1o
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
> -- 
> 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/CA%2B%3DOU3V6vOGGaG7_M9xmEPY232%3DpVXqMKSrxH-hMbCOwDo2Axg%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

-- 
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/5256C126.5080909%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.


Re: readonly_fields depending on request

2013-10-10 Thread Timothy W. Cook
On Thu, Oct 10, 2013 at 10:04 AM, Roberto López López
wrote:

> This is, for example, my code overriding get_readonly_fields():
>
> def get_readonly_fields(self, request, obj=None):
> readonly = super(NewsAdmin, self).get_readonly_fields(request, obj)
> if request.user.groups.filter(name__exact='administration') or
> request.user.is_superuser:
> return readonly
> else:
> import itertools
> return itertools.chain(readonly, ('is_featured',))
>
>
>
I do not understand your logic as it compares to your description of the
problem.

For your described problem:
If the user is_superuser then you shouldn't set read_only at all.

If a user is in a specific set of users then set read_only= ['field1',
'field2',] as appropriate.

It is a pretty simple problem it looks like you are making it far too
complex. 










>
> On 10/10/2013 02:45 PM, Roberto López López wrote:
> > Hi,
> >
> > In my project I make use of django-admin. I need to have different
> > readonly_fields depending on the user is connected, thus administrators
> > will be able to modify all fields, and other users less fields. Which
> > method do I have to override? I have already tried
> > ModelAdmin.get_readonly_fields() and ModelAdmin.get_form(). But no
> success.
> >
> > Any other suggestions?
> >
> > Thanks!
> >
> > Roberto
> >
> >
>
>
> --
>
> Roberto López López
> System Developer
> Parallab, Uni Computing
> +47 55584091
>
> --
> 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/5256A5E2.9020505%40uni.no.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
MLHIM VIP Signup: http://goo.gl/22B0U

Timothy Cook, MSc   +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

-- 
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/CA%2B%3DOU3U69QzDSbc0qyJ_zbgA3BYHCi5zK3%3DaAra-saAq%2Bvj3EA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Looking for a way to detect changes in database records with low storage footprint

2013-10-10 Thread C. Kirby
You could grab the __dict__ of the instance and use that.

import hashlib

hash = hashlib.md5()
hash.update(str(MyModel.objects.get(pk = 1).__dict__))
hash.digest()

On Thursday, October 10, 2013 8:55:27 AM UTC-5, DJ-Tom wrote:
>
>
> Thanks, but *how* can I create a hash from a database object in Django - 
> is there a generic method to iterate over all (or only specific) fields and 
> get a hash value?
>
> Am Mittwoch, 9. Oktober 2013 19:07:54 UTC+2 schrieb Nikolas 
> Stevenson-Molnar:
>>
>> A hash should work fine. Alternatively, you could diff the two records, 
>> using something like difflib: 
>> http://docs.python.org/2/library/difflib.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/77cbde22-923a-49ff-8d6e-ee91db6adbe3%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Extension to QuerySet.values()

2013-10-10 Thread Ramiro Morales
On Oct 10, 2013 10:02 AM, "Arnaud Delobelle"  wrote:
>
> Hi Russ,
>
> Thanks for the feedback.  I agree that this could possibly be integrated
into the values() method.  I just used a new method in order to minimise
interference with our existing code.  I'll read the 'contributing' document
then see if I can find a bit of spare time to do this properly!
>
FYI IIUC this has been reported in ticket 16735:

https://code.djangoproject.com/ticket/16735

>
> --
> Arnaud
>
>
> On Thursday, 10 October 2013 00:44:45 UTC+1, Russell Keith-Magee wrote:
>>
>> Hi Arnaud,
>>
>> I can see value in the feature you're describing here.
>>
>> From a design perspective, my question would be whether a whole new
method is needed, or whether it could be integrated into the existing
values() method. There will be some complications around the 'flat' key,
but its worth exploring the possibilities before we introduce a whole new
API entry point.
>>
>> If you're interested in taking this to the next level, we'll need tests
and documentation for the new feature. If you want to discuss finer details
of the API, the django-developers mailing list is a better forum. Our
contribution process is also documented; if you want to get involved in
contributing to the internals of Django, it's worth giving this document a
read [1].
>>
>> [1] https://docs.djangoproject.com/en/1.5/internals/contributing/
>>
>> Yours,
>> Russ Magee %-)
>>
>> On Wed, Oct 9, 2013 at 6:19 PM, Arnaud Delobelle 
wrote:
>>>
>>> Hi there,
>>>
>>> I quite often find that when using queryset.values() I would like to be
able to define myself the values of the keys, especially when they span
models:
>>>
>>> e.g.
>>>
>>>my_query_set.values('foo__bar__baz', 'quux',
'another__long__field__name')
>>>
>>> Then I end up with dictionaries with unnecessarily long keys.  What I'd
like to be able to do is something like:
>>>
>>> my_query_set.values('quux', baz='foo__bar__baz',
name='another__long__field__name')
>>>
>>> Executing this would yield dictionaries of the type:
>>>
>>> {'quux': 2, 'baz': 'type 2', 'name': 'Frobulon'}
>>>
>>>
>>> I've had a quick look at the ValuesQuerySet class and there seems to be
a simple enough way to get this feature.  I'm presenting it in the form of
a new ValuesQuerySet subclass and a monkey patch to the parent QuerySet.
 It's not unlikely that it will break some things as this is my first peek
into the QuerySet class.  I'd like to know if this is something that other
people feel the need for and if it is worth pushing for inclusion of such a
feature into django.
>>>
>>> Cheers,
>>>
>>> Arnaud
>>>
>>> 
>>>
>>> from django.db.models.query import QuerySet, ValuesQuerySet
>>>
>>>
>>> class ValuesDictQuerySet(ValuesQuerySet):
>>>
>>> def iterator(self):
>>> # Purge any extra columns that haven't been explicitly asked for
>>> extra_names = list(self.query.extra_select)
>>> field_map = self.field_map
>>> field_names = [field_map.get(fname, fname) for fname in
self.field_names]
>>> aggregate_names = list(self.query.aggregate_select)
>>>
>>> names = extra_names + field_names + aggregate_names
>>>
>>> for row in self.query.get_compiler(self.db).results_iter():
>>> yield dict(zip(names, row))
>>>
>>> def _clone(self, klass=None, setup=False, **kwargs):
>>> c = super(ValuesDictQuerySet, self)._clone(klass, **kwargs)
>>> c.field_map = self.field_map
>>> return c
>>>
>>>
>>> def QuerySet_values_dict(self, *field_list, **field_dict):
>>> fields = list(field_list)
>>> fields.extend(field_dict.values())
>>> field_map = dict(zip(field_dict.values(), field_dict.keys()))
>>> return self._clone(klass=ValuesDictQuerySet, setup=True,
_fields=fields, field_map=field_map)
>>>
>>>
>>> # Now we monkey-patch QuerySet with the new method
>>> QuerySet.values_dict = QuerySet_values_dict
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@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/d4f8d6f0-3723-44d5-991a-9c6b3c13165d%40googlegroups.com
.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
> --
> 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

Re: Looking for a way to detect changes in database records with low storage footprint

2013-10-10 Thread DJ-Tom

Thanks, but *how* can I create a hash from a database object in Django - is 
there a generic method to iterate over all (or only specific) fields and 
get a hash value?

Am Mittwoch, 9. Oktober 2013 19:07:54 UTC+2 schrieb Nikolas 
Stevenson-Molnar:
>
> A hash should work fine. Alternatively, you could diff the two records, 
> using something like difflib: 
> http://docs.python.org/2/library/difflib.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/44f13037-4973-487a-86ac-ce617ddaf583%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: readonly_fields depending on request

2013-10-10 Thread Roberto López López
This is, for example, my code overriding get_readonly_fields():

def get_readonly_fields(self, request, obj=None):
readonly = super(NewsAdmin, self).get_readonly_fields(request, obj)
if request.user.groups.filter(name__exact='administration') or
request.user.is_superuser:
return readonly
else:
import itertools
return itertools.chain(readonly, ('is_featured',))



On 10/10/2013 02:45 PM, Roberto López López wrote:
> Hi,
>
> In my project I make use of django-admin. I need to have different
> readonly_fields depending on the user is connected, thus administrators
> will be able to modify all fields, and other users less fields. Which
> method do I have to override? I have already tried
> ModelAdmin.get_readonly_fields() and ModelAdmin.get_form(). But no success.
>
> Any other suggestions?
>
> Thanks!
>
> Roberto
>
>


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

-- 
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/5256A5E2.9020505%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Extension to QuerySet.values()

2013-10-10 Thread Arnaud Delobelle
Hi Russ,

Thanks for the feedback.  I agree that this could possibly be integrated 
into the values() method.  I just used a new method in order to minimise 
interference with our existing code.  I'll read the 'contributing' document 
then see if I can find a bit of spare time to do this properly!

Cheers,

-- 
Arnaud

On Thursday, 10 October 2013 00:44:45 UTC+1, Russell Keith-Magee wrote:
>
> Hi Arnaud,
>
> I can see value in the feature you're describing here.
>
> From a design perspective, my question would be whether a whole new method 
> is needed, or whether it could be integrated into the existing values() 
> method. There will be some complications around the 'flat' key, but its 
> worth exploring the possibilities before we introduce a whole new API entry 
> point.
>
> If you're interested in taking this to the next level, we'll need tests 
> and documentation for the new feature. If you want to discuss finer details 
> of the API, the django-developers mailing list is a better forum. Our 
> contribution process is also documented; if you want to get involved in 
> contributing to the internals of Django, it's worth giving this document a 
> read [1].
>
> [1] https://docs.djangoproject.com/en/1.5/internals/contributing/
>
> Yours,
> Russ Magee %-)
>
> On Wed, Oct 9, 2013 at 6:19 PM, Arnaud Delobelle 
>  > wrote:
>
>> Hi there,
>>
>> I quite often find that when using queryset.values() I would like to be 
>> able to define myself the values of the keys, especially when they span 
>> models:
>>
>> e.g.
>>
>>my_query_set.values('foo__bar__baz', 'quux', 
>> 'another__long__field__name')
>>
>> Then I end up with dictionaries with unnecessarily long keys.  What I'd 
>> like to be able to do is something like:
>>
>> my_query_set.values('quux', baz='foo__bar__baz', 
>> name='another__long__field__name')
>>
>> Executing this would yield dictionaries of the type:
>>
>> {'quux': 2, 'baz': 'type 2', 'name': 'Frobulon'}
>>
>>
>> I've had a quick look at the ValuesQuerySet class and there seems to be a 
>> simple enough way to get this feature.  I'm presenting it in the form of a 
>> new ValuesQuerySet subclass and a monkey patch to the parent QuerySet. 
>>  It's not unlikely that it will break some things as this is my first peek 
>> into the QuerySet class.  I'd like to know if this is something that other 
>> people feel the need for and if it is worth pushing for inclusion of such a 
>> feature into django.
>>
>> Cheers,
>>
>> Arnaud
>>
>> 
>>
>> from django.db.models.query import QuerySet, ValuesQuerySet
>>
>>
>> class ValuesDictQuerySet(ValuesQuerySet):
>>
>> def iterator(self):
>> # Purge any extra columns that haven't been explicitly asked for
>> extra_names = list(self.query.extra_select)
>> field_map = self.field_map
>> field_names = [field_map.get(fname, fname) for fname in 
>> self.field_names]
>> aggregate_names = list(self.query.aggregate_select)
>>
>> names = extra_names + field_names + aggregate_names
>>
>> for row in self.query.get_compiler(self.db).results_iter():
>> yield dict(zip(names, row))
>>
>> def _clone(self, klass=None, setup=False, **kwargs):
>> c = super(ValuesDictQuerySet, self)._clone(klass, **kwargs)
>> c.field_map = self.field_map
>> return c
>>
>>
>> def QuerySet_values_dict(self, *field_list, **field_dict):
>> fields = list(field_list)
>> fields.extend(field_dict.values())
>> field_map = dict(zip(field_dict.values(), field_dict.keys()))
>> return self._clone(klass=ValuesDictQuerySet, setup=True, 
>> _fields=fields, field_map=field_map)
>>
>>
>> # Now we monkey-patch QuerySet with the new method
>> QuerySet.values_dict = QuerySet_values_dict
>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/d4f8d6f0-3723-44d5-991a-9c6b3c13165d%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
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/24ceded6-9bb8-454b-968e-f3883fe4c14e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: readonly_fields depending on request

2013-10-10 Thread Timothy W. Cook
Can you post the code you tried with get_form()?  It should be the solution.



On Thu, Oct 10, 2013 at 9:45 AM, Roberto López López
wrote:

> Hi,
>
> In my project I make use of django-admin. I need to have different
> readonly_fields depending on the user is connected, thus administrators
> will be able to modify all fields, and other users less fields. Which
> method do I have to override? I have already tried
> ModelAdmin.get_readonly_fields() and ModelAdmin.get_form(). But no success.
>
> Any other suggestions?
>
> Thanks!
>
> Roberto
>
>
> --
> 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/5256A163.3000907%40uni.no.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
MLHIM VIP Signup: http://goo.gl/22B0U

Timothy Cook, MSc   +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

-- 
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/CA%2B%3DOU3V6vOGGaG7_M9xmEPY232%3DpVXqMKSrxH-hMbCOwDo2Axg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


readonly_fields depending on request

2013-10-10 Thread Roberto López López
Hi,

In my project I make use of django-admin. I need to have different
readonly_fields depending on the user is connected, thus administrators
will be able to modify all fields, and other users less fields. Which
method do I have to override? I have already tried
ModelAdmin.get_readonly_fields() and ModelAdmin.get_form(). But no success.

Any other suggestions?

Thanks!

Roberto


-- 
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/5256A163.3000907%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.


Combining example Polls app with django-registration

2013-10-10 Thread Alex Koudrin
I'm learning Django (Ubuntu 13.04, Python 2.7, Django 1.5, Postgres 9.2, 
Bootstrap 3.0). As my first effort I got the Polls app going from the Django 
1.5 tutorial . I 
then installed django-registration 
1.0and these 
templates  to 
make it work. I chose that package for authentication as opposed to 
django-allauth  as a result 
of my question on 
StackOverflow.
 


What I want to do now is to integrate these two apps so that the polls are 
not anonymous. After the poll results have been collected, a script is run 
to analyse the results and send an email to each user about how they did as 
compared to total or average. The script and the emailing could be done via 
Python, but even better should really be initialised via the Admin 
interface by site admin.

At first pass I was thinking roughly the following. The poll & choice could 
be simplified down to just a numeric answer to a question. At database 
level we would need a separate table. The primary key would be the userid. 
Each column would store one answer per. I'm guessing this would need a 
class PollsResults in model.py that would include defining the primary key 
as "User", which should exist via django-registration. Exactly how to do 
that and what follows gets a bit hazy to me at the moment.

At the moment my knowledge of Django is so light that I'm struggling to put 
two and two together in an elegant way. I have briefly looked at Light 
Bird's Questionnaire , but 
decided it was too complicated using his own library of modular class based 
views. I'd like to keep it as simple as possible, using as much of 
out-of-the-box Django 1.5 functionality as possible.

I also looked at Pinax, but it seems to be stuck in dark ages with latest 
stuff supporting Django 1.4 and Bootstrap 2.x. Documentation looks poor 
too. It looks like a great concept - half-way house between a web framework 
and a CMS. But if only it had a larger following and be more up-to-date 
with a variety of starter projects (e.g. a Questionnaire/Polls type starter 
project where users enter data and then some processing happens etc).

I'm sure it's a simple exercise for any good Django dev to essentially 
combine django-registration with a result against each user, which can then 
be processed/emailed/etc.

Could anyone give any hints or maybe even point me to an example of 
something similar that could give me a starting point of modifying things 
rather than creating from scratch?

-- 
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/c431b06a-6bc2-4fca-80b2-73543af2540e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Advanced Tutorial (how to write reusable app), last step does not work

2013-10-10 Thread Sebastian Wade
hi,guys
  u should read this content: 
https://docs.djangoproject.com/en/1.0/intro/tutorial04/

> We’re using two generic views here: object_list() and object_detail(). 
> Respectively, those two views abstract the concepts of “display a list of 
> objects” and “display a detail page for a particular type of object.”
>
>
>- Each generic view needs to know what data it will be acting upon. 
>This data is provided in a dictionary. The queryset key in this 
>dictionary points to the list of objects to be manipulated by the generic 
>view.
>- The object_detail() generic view expects the ID value captured from 
>the URL to be called "object_id", so we’ve changed poll_id to object_id 
> for 
>the generic views.
>- We’ve added a name, poll_results, to the results view so that we 
>have a way to refer to its URL later on (see the documentation about 
> naming 
>URL 
> patterns
>  for 
>information). We’re also using the url() function from
>django.conf.urls.defaults here. It’s a good habit to use url() when 
>you are providing a pattern name like this.
>
> By default, the object_detail() generic view uses a template called  name>/_detail.html. In our case, it’ll use the template 
> "polls/poll_detail.html". Thus, rename your polls/detail.html template to 
> polls/poll_detail.html, and change the render_to_response() line in vote()
> .
>
> Similarly, the object_list() generic view uses a template called  name>/_list.html. Thus, renamepolls/index.html to 
> polls/poll_list.html.
>
> Because we have more than one entry in the URLconf that uses 
> object_detail() for the polls app, we manually specify a template name 
> for the results view: template_name='polls/results.html'. Otherwise, both 
> views would use the same template. Note that we use dict() to return an 
> altered dictionary in place.
>


On Saturday, July 27, 2013 8:20:26 AM UTC+8, Cate Liu wrote:
>
>
> I am a new newbie to Django.  Great tutorial BTW.  I followed it to the T 
> and 99.9% worked.
> Except the last step in the Advanced tutorial, the step 3 in 'Using your 
> own package'.
> I could see http://127.0.0.1:8000/admin/ and create polls without any 
> problem.
> But http://127.0.0.1:8000/polls/ would give me the following error.
>
> I see there are two problems.
> 1. /Users/nnn/django_exercises/mysite/templates/polls/index.html is the 
> wrong location, it should be 
> $$/django_polls/polls/templates/polls/index.html.
> 2. What is polls/poll_list.html?  Nowhere in the tutorial ever created 
> this file, no?
>
> Thanks for any advice.
>
>
>
> --
> TemplateDoesNotExist at /polls/ 
>
> polls/index.html, polls/poll_list.html
>
>  Request Method: GET  Request URL: http://127.0.0.1:8000/polls/  Django 
> Version: 1.5.1  Exception Type: TemplateDoesNotExist  Exception Value: 
>
> polls/index.html, polls/poll_list.html
>
>  Exception Location: 
> /Library/Python/2.7/site-packages/django/template/loader.py 
> in select_template, line 194  Python Executable: /usr/bin/python  Python 
> Version: 2.7.2  Python Path: 
>
> ['/Users/nnn/django_exercises/mysite',
>  '/Users/nnn/py_pkg/lib/python/django_polls-0.1-py2.7.egg',
>  '/Users/nnn/py_pkg/lib/python',
>  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
>  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
>  '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
>  '/Library/Python/2.7/site-packages']
>
>  Server time: Fri, 26 Jul 2013 16:59:14 -0700
>
> Template-loader postmortem 
>
> Django tried loading these templates, in this order:
>
>- Using loader django.template.loaders.filesystem.Loader: 
>   - /Users/nnn/django_exercises/mysite/templates/polls/index.html, 
>   polls/poll_list.html (File does not exist)
>- Using loader django.template.loaders.app_directories.Loader: 
>   - 
> /Library/Python/2.7/site-packages/django/contrib/auth/templates/polls/index.html,
>  
>   polls/poll_list.html (File does not exist)
>   - 
> /Library/Python/2.7/site-packages/django/contrib/admin/templates/polls/index.html,
>  
>   polls/poll_list.html 

Re: Advanced Tutorial (how to write reusable app), last step does not work

2013-10-10 Thread Sebastian Wade
hi, guys
hoped this may help you.
https://docs.djangoproject.com/en/1.0/intro/tutorial04/

> We’re using two generic views here: object_list() and object_detail(). 
> Respectively, those two views abstract the concepts of “display a list of 
> objects” and “display a detail page for a particular type of object.”
>
>
>- Each generic view needs to know what data it will be acting upon. 
>This data is provided in a dictionary. The queryset key in this 
>dictionary points to the list of objects to be manipulated by the generic 
>view.
>- The object_detail() generic view expects the ID value captured from 
>the URL to be called "object_id", so we’ve changed poll_id to object_id 
> for 
>the generic views.
>- We’ve added a name, poll_results, to the results view so that we 
>have a way to refer to its URL later on (see the documentation about 
> naming 
>URL 
> patterns
>  for 
>information). We’re also using the url() function from
>django.conf.urls.defaults here. It’s a good habit to use url() when 
>you are providing a pattern name like this.
>
> By default, the object_detail() generic view uses a template called  name>/_detail.html. In our case, it’ll use the template 
> "polls/poll_detail.html". Thus, rename your polls/detail.html template to 
> polls/poll_detail.html, and change the render_to_response() line in vote()
> .
>
> Similarly, the object_list() generic view uses a template called  name>/_list.html. Thus, renamepolls/index.html to 
> polls/poll_list.html.
>
> Because we have more than one entry in the URLconf that uses 
> object_detail() for the polls app, we manually specify a template name 
> for the results view: template_name='polls/results.html'. Otherwise, both 
> views would use the same template. Note that we use dict() to return an 
> altered dictionary in place.
>
On Saturday, July 27, 2013 8:20:26 AM UTC+8, Cate Liu wrote:
>
>
> I am a new newbie to Django.  Great tutorial BTW.  I followed it to the T 
> and 99.9% worked.
> Except the last step in the Advanced tutorial, the step 3 in 'Using your 
> own package'.
> I could see http://127.0.0.1:8000/admin/ and create polls without any 
> problem.
> But http://127.0.0.1:8000/polls/ would give me the following error.
>
> I see there are two problems.
> 1. /Users/nnn/django_exercises/mysite/templates/polls/index.html is the 
> wrong location, it should be 
> $$/django_polls/polls/templates/polls/index.html.
> 2. What is polls/poll_list.html?  Nowhere in the tutorial ever created 
> this file, no?
>
> Thanks for any advice.
>
>
>
> --
> TemplateDoesNotExist at /polls/ 
>
> polls/index.html, polls/poll_list.html
>
>  Request Method: GET  Request URL: http://127.0.0.1:8000/polls/  Django 
> Version: 1.5.1  Exception Type: TemplateDoesNotExist  Exception Value: 
>
> polls/index.html, polls/poll_list.html
>
>  Exception Location: 
> /Library/Python/2.7/site-packages/django/template/loader.py 
> in select_template, line 194  Python Executable: /usr/bin/python  Python 
> Version: 2.7.2  Python Path: 
>
> ['/Users/nnn/django_exercises/mysite',
>  '/Users/nnn/py_pkg/lib/python/django_polls-0.1-py2.7.egg',
>  '/Users/nnn/py_pkg/lib/python',
>  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
>  '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
>  '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
>  
> '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
>  '/Library/Python/2.7/site-packages']
>
>  Server time: Fri, 26 Jul 2013 16:59:14 -0700
>
> Template-loader postmortem 
>
> Django tried loading these templates, in this order:
>
>- Using loader django.template.loaders.filesystem.Loader: 
>   - /Users/nnn/django_exercises/mysite/templates/polls/index.html, 
>   polls/poll_list.html (File does not exist)
>- Using loader django.template.loaders.app_directories.Loader: 
>   - 
> /Library/Python/2.7/site-packages/django/contrib/auth/templates/polls/index.html,
>  
>   polls/poll_list.html (File does not exist)
>   - 
> /Library/Python/2.7/site-packages/django/contrib/admin/templates/polls/index.html,
>  
>   polls/poll_list.html (File 

Re: Table in models.py not being created during syncdb

2013-10-10 Thread Sergiy Khohlov
Have you added schedule to installed application list  ?
Many thanks,

Serge


+380 636150445
skype: skhohlov


On Wed, Oct 9, 2013 at 4:11 PM, Edward Lazarenko  wrote:
> Can you tell what did you exactly do, to make it work?
>
> On Wednesday, March 31, 2010 10:16:11 PM UTC+5, wchildsuk wrote:
>>
>> Hi,
>>
>> I'm using the django app, django-schedule (http://github.com/thauber/
>> django-schedule) and am adding an additional table to map users to
>> calendars (see line 253 on dpaste).  When I run syncdb it completely
>> ignores my table and doesn't through any errors. Can anyone shed any
>> light on way it might be being igored?
>>
>> My models file is available here:
>>
>> http://dpaste.com/178158/
>>
>> Thanks in advance
>>
>> Wes
>
> --
> 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/0573be21-ab52-44ec-a005-e8efb3ea09bd%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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/CADTRxJPhp9r39dk%3D%2Bnc6Ai515c5x5eK7DjRWT1QbboZqVUp%3D4w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Retrieving json stored in TextField as json

2013-10-10 Thread Marc Aymerich
Hi Rafael, thanks !
I forgot to mention that I was already using django-jsonfield
https://github.com/bradjasper/django-jsonfield
and now I've tried with django-json-field but with the same unfortunate result:

TimeSerie.objects.filter(type='cpu').values('value')
[{'value': '{"scheduled":2,"total":864,"15min":0.38,"1min":0.3,"5min":0.48}'},
{'value': '{"scheduled":2,"total":859,"15min":0.34,"1min":0.23,"5min":0.32}'},
{'value': '{"scheduled":2,"total":849,"15min":0.33,"1min":0.51,"5min":0.32}'}]

did I missed something?


On Thu, Oct 10, 2013 at 1:16 AM, Rafael Durán Castañeda
 wrote:
> I'm using django-json-field [1] for solving the same problem.
>
> [1] https://github.com/derek-schaefer/django-json-field
>
> HTH
> El 09/10/2013, a las 16:01, Marc Aymerich  escribió:
>
>> Hi,
>> I'm storing large volumes of json data in a TextFields, Then I have a
>> view that converts this text data into JSON, but this silly operation
>> requires a considerable amount of resources for a large dataset.
>>
>> It would be nice if I'm able to retrieve native JSON directly from the 
>> database.
>>
>> As you can see value is "almost" json, the only problem is that is
>> wrapped around quotes :)
>>
> TimeSerie.objects.filter(type='cpu').values('value')
>> [{'value': 
>> '{"scheduled":2,"total":864,"15min":0.38,"1min":0.3,"5min":0.48}'},
>> {'value': 
>> '{"scheduled":2,"total":859,"15min":0.34,"1min":0.23,"5min":0.32}'},
>> {'value': 
>> '{"scheduled":2,"total":849,"15min":0.33,"1min":0.51,"5min":0.32}'},
>> {'value': '{"scheduled":2,"total":814,"15min":0.3,"1min":0.2,"5min":0.25}'},
>> {'value': 
>> '{"scheduled":2,"total":817,"15min":0.25,"1min":0.14,"5min":0.17}'},
>> {'value': 
>> '{"scheduled":2,"total":815,"15min":0.22,"1min":0.18,"5min":0.14}'}]
>>
>> Any suggestion in how I can speed this up by avoiding to convert each
>> element to json by iterating on the query results?
>>
>> I'm using psotgresql 9.3 with native json support, not sure if it is
>> relevant or not :)
>>
>> --
>> Marc
>>
>> --
>> 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/CA%2BDCN_vTbC0-yOt7cuToYLZSOD%2B%3DZCubLOjgkpu-MyB1VxbGMA%40mail.gmail.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> 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/646FABCC-B4DB-4EE7-BC54-B0C5A2C7C25F%40gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.



-- 
Marc

-- 
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/CA%2BDCN_uq3OEKEEBrQnFGrDnvWTE0_G9UWG4k-EXPyz36H4rTDw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.