Re: How to change the {{ form.as_table }}

2013-04-08 Thread Venkatraman S
Also, do have a look at crispy-forms.

-Venkat


On Mon, Apr 8, 2013 at 7:59 AM, Ben Carleton  wrote:

>  You can use the label attribute on your form fields to override the
> default labels:
>
> dn = forms.CharField(label="dn")
> cv = forms.CharField(label="cv")
>
> -- Ben
>
>
> On 4/7/2013 10:11 PM, lx wrote:
>
> hi, I'm using the forms,and* the code is:*
>
>  from django import forms
> class dcForm(forms.Form):
> """
> """
> TOPIC_CHOICES = ( ('cnccdn', 'cnccdn.com'), ('lxcdns', 'lxcdns.com'),
> ('wscdns', 'wscdns.com'),)
> dnssystem = forms.ChoiceField(choices=TOPIC_CHOICES)
> dn = forms.CharField()
> cv = forms.CharField()
>
>  *the template is:*
>
>   enctype="multipart/form-data"{% endif %}>
>  style="background-color:#99;text-align:top;">
> {{ form.as_table }}
>
>
>
>  the WEB is:
> [image: 内嵌图片 1]
>
>  *I want to replace the "Dnssystem, Dn, Cv" to "dnssystem, dn, cv".*
> How to solve it?
> Thank you
>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> 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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


<>

Good tutorials on celeryd as a daemon needed?

2013-04-08 Thread sparky
Hi Django people,

I'm finding it difficult to get my head around running celeryd as a daemon 
from the docs on Ubuntu. Does anyone know of any good tutorials or reading 
to help me along?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Django Generic ForeignKey vs Multiple Foreign Key Fields

2013-04-08 Thread Arun Prabhakar
# I have 2 models, say A and B
class A(models.Model):
pass

class B(models.Model):
pass

"""
Now my query is which of the following would you choose and why?
"""

class GenericFK(models.Model):

content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
#-- vs --

class MultipleFK(models.Model):
a = models.ForeignKey(A, null=True)
b = models.ForeignKey(B, null=True)


Thank you.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django Generic ForeignKey vs Multiple Foreign Key Fields

2013-04-08 Thread Martin J. Laubach
  It's simply a question of what you want to model.

  *GenericFK* means for each instance "I have a relationship with some 
other (undefined) entity". *MultipleFK* means "I have relationships with 
both well-known entities A and B". Totally different things.

  Cheers,

mjl


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Good tutorials on celeryd as a daemon needed?

2013-04-08 Thread Marcos Moyano
http://ask.github.io/celery/cookbook/daemonizing.html


On Mon, Apr 8, 2013 at 6:01 AM, sparky  wrote:

> Hi Django people,
>
> I'm finding it difficult to get my head around running celeryd as a daemon
> from the docs on Ubuntu. Does anyone know of any good tutorials or reading
> to help me along?
>
> Thanks
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Some people, when confronted with a problem, think “I know, I'll use
regular expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




custom logging with keywords

2013-04-08 Thread Gabriel - Iulian Dumbrava
Hi guys,

some time ago a post was made on this group (I think) about a custom logger 
that you can use to easy add log messages with specific keywords that may 
appear in the admin as a filter.


Does any of you know what this package is?

I simply can't find the entry anymore.

Thanks!
Gabriel

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django Generic ForeignKey vs Multiple Foreign Key Fields

2013-04-08 Thread Arun Prabhakar
Hi Martin, 

A and B are known, and more can come in the future, so it would seem 
generic is the way to go, but then I dont want to reference on all tables 
in django.
But using the FK has problem of introducing alter tables later.

Confused about going with which approach.

What do you suggest?

On Monday, April 8, 2013 3:19:07 PM UTC+5:30, Martin J. Laubach wrote:
>
>   It's simply a question of what you want to model.
>
>   *GenericFK* means for each instance "I have a relationship with some 
> other (undefined) entity". *MultipleFK* means "I have relationships with 
> both well-known entities A and B". Totally different things.
>
>   Cheers,
>
> mjl
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Implementing User login expiration

2013-04-08 Thread Tom Evans
On Sat, Apr 6, 2013 at 12:24 AM, John DeRosa
 wrote:
> I have a Profile table that's 1:1 with the User table. Each Profile row has
> an account_expiration field.
>
> I want to invalidate users when their accounts expire. By "invalidate", I
> mean: They can't log in, and they can't use the system any more.
>
> The closer I look, the more complicated it seems.
>
> Adding an expiration date check to our authentication backend is the easy
> part. The hard part is what to do about users who are currently logged in?
> They have Session objects in the database, and the session cache. (We use
> django.contrib.sessions.backends.cached_db.) I could make a periodic task
> that deletes the session objects of expired accounts, but it would also have
> to find the expired objects in the cache. This starts to feel unwieldy and
> fragile.
>
> I could crank down SESSION_COOKIE_AGE to one hour, but that would be ugly.
>
> I'm wondering if I'm over-thinking this. Has anyone implemented account
> expiration in a way that deals with users already logged in?
>

I defined a model SessionAudit, which has a foreign key to user, and
fields for session id, ip address, user agent, and created and
modified timestamps.

I've then added a piece of middleware, which ensures that each
authenticated user also has a corresponding SessionAudit instance.

I've added a post_delete signal to Session objects, so that when a
Session is deleted, any corresponding SessionAudit objects are also
removed.

Finally, I've added a view to our users page, allowing an admin to
list and examine details about a users session, and allow them to
destroy/revoke a users session. This isn't in django's admin
interface, it is in our own custom interface, but I would have thought
this could be similarly modelled in Django's admin.

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




creating resource with django-tastypie

2013-04-08 Thread psychok7
guys i am having problems creating a new resource with django tastypie. i 
get the following error:

class RatingResource(ModelResource):
city = fields.ForeignKey(CityResource, 'city')
user_id = fields.ForeignKey(UserResource, 'user')
class Meta:
queryset = Rating.objects.all()
resource_name = 'rating'
#authentication = BasicAuthentication()
#authorization = DjangoAuthorization()

curl --dump-header - -H "Content-Type: application/json" -X POST --data '{city: 
"/api/smarturbia/city/35/", comment: "teste do php", id: "4", resource_uri: 
"/api/smarturbia/rating/4/", rating: "3",user_id: 
"/api/smarturbia/auth/user/2/"}' http://127.0.0.1:8000/api/smarturbia/rating/
HTTP/1.0 500 INTERNAL SERVER ERROR
Date: Mon, 08 Apr 2013 10:36:34 GMT
Server: WSGIServer/0.1 Python/2.7.3
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Content-Type: application/json
Access-Control-Allow-Headers: Content-Type,*
Access-Control-Allow-Credentials: true

{"error_message": "Expecting property name: line 1 column 1 (char 1)", 
"traceback": "Traceback (most recent call last):\n\n  File 
\"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 202, in 
wrapper\nresponse = callback(request, *args, **kwargs)\n\n  File 
\"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 440, in 
dispatch_list\nreturn self.dispatch('list', request, **kwargs)\n\n  File 
\"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 472, in 
dispatch\nresponse = method(request, **kwargs)\n\n  File 
\"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 1325, in 
post_list\ndeserialized = self.deserialize(request, request.raw_post_data, 
format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n  File 
\"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 389, in 
deserialize\ndeserialized = self._meta.serializer.deserialize(data, 
format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n  File 
\"/usr/local/lib/python2.7/dist-packages/tastypie/serializers.py\", line 205, 
in deserialize\ndeserialized = getattr(self, \"from_%s\" % 
desired_format)(content)\n\n  File 
\"/usr/local/lib/python2.7/dist-packages/tastypie/serializers.py\", line 359, 
in from_json\nreturn simplejson.loads(content)\n\n  File 
\"/usr/lib/python2.7/dist-packages/simplejson/__init__.py\", line 413, in 
loads\nreturn _default_decoder.decode(s)\n\n  File 
\"/usr/lib/python2.7/dist-packages/simplejson/decoder.py\", line 402, in 
decode\nobj, end = self.raw_decode(s, idx=_w(s, 0).end())\n\n  File 
\"/usr/lib/python2.7/dist-packages/simplejson/decoder.py\", line 418, in 
raw_decode\nobj, end = self.scan_once(s, idx)\n\nJSONDecodeError: Expecting 
property name: line 1 column 1 (char 1)\n"}


any ideas?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: creating resource with django-tastypie

2013-04-08 Thread psychok7
it was a quoting problem.. but now i get another error:

HTTP/1.0 401 UNAUTHORIZED

curl --dump-header - -H "Content-Type: application/json" -X POST --data 
'{"city": "/api/smart/city/35/", "comment": "teste do php", "id": "4", 
"resource_uri": "/api/smart/rating/4/", "rating": "3","user_id": 
"/api/smart/auth/user/2/"}' http://localhost:8000/api/smart/rating/ HTTP/1.0 
401 UNAUTHORIZED Date: Mon, 08 Apr 2013 10:52:44 GMT Server: WSGIServer/0.1 
Python/2.7.3 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: 
POST,GET,OPTIONS,PUT,DELETE Content-Type: text/html; charset=utf-8 
Access-Control-Allow-Headers: Content-Type,* 
Access-Control-Allow-Credentials: true

On Monday, April 8, 2013 11:41:11 AM UTC+1, psychok7 wrote:
>
> guys i am having problems creating a new resource with django tastypie. i 
> get the following error:
>
> class RatingResource(ModelResource):
> city = fields.ForeignKey(CityResource, 'city')
> user_id = fields.ForeignKey(UserResource, 'user')
> class Meta:
> queryset = Rating.objects.all()
> resource_name = 'rating'
> #authentication = BasicAuthentication()
> #authorization = DjangoAuthorization()
>
> curl --dump-header - -H "Content-Type: application/json" -X POST --data 
> '{city: "/api/smarturbia/city/35/", comment: "teste do php", id: "4", 
> resource_uri: "/api/smarturbia/rating/4/", rating: "3",user_id: 
> "/api/smarturbia/auth/user/2/"}' http://127.0.0.1:8000/api/smarturbia/rating/
> HTTP/1.0  500 INTERNAL 
> SERVER ERROR
> Date: Mon, 08 Apr 2013 10:36:34 GMT
> Server: WSGIServer/0.1 Python/2.7.3
> Access-Control-Allow-Origin: *
> Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
> Content-Type: application/json
> Access-Control-Allow-Headers: Content-Type,*
> Access-Control-Allow-Credentials: true
>
> {"error_message": "Expecting property name: line 1 column 1 (char 1)", 
> "traceback": "Traceback (most recent call last):\n\n  File 
> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 202, 
> in wrapper\nresponse = callback(request, *args, **kwargs)\n\n  File 
> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 440, 
> in dispatch_list\nreturn self.dispatch('list', request, **kwargs)\n\n  
> File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 
> 472, in dispatch\nresponse = method(request, **kwargs)\n\n  File 
> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 1325, 
> in post_list\ndeserialized = self.deserialize(request, 
> request.raw_post_data, format=request.META.get('CONTENT_TYPE', 
> 'application/json'))\n\n  File 
> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 389, 
> in deserialize\ndeserialized = self._meta.serializer.deserialize(data, 
> format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n  File 
> \"/usr/local/lib/python2.7/dist-packages/tastypie/serializers.py\", line 205, 
> in deserialize\ndeserialized = getattr(self, \"from_%s\" % 
> desired_format)(content)\n\n  File 
> \"/usr/local/lib/python2.7/dist-packages/tastypie/serializers.py\", line 359, 
> in from_json\nreturn simplejson.loads(content)\n\n  File 
> \"/usr/lib/python2.7/dist-packages/simplejson/__init__.py\", line 413, in 
> loads\nreturn _default_decoder.decode(s)\n\n  File 
> \"/usr/lib/python2.7/dist-packages/simplejson/decoder.py\", line 402, in 
> decode\nobj, end = self.raw_decode(s, idx=_w(s, 0).end())\n\n  File 
> \"/usr/lib/python2.7/dist-packages/simplejson/decoder.py\", line 418, in 
> raw_decode\nobj, end = self.scan_once(s, idx)\n\nJSONDecodeError: 
> Expecting property name: line 1 column 1 (char 1)\n"}
>
>
> any ideas?
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Getting an AttributeError while creating a Django project

2013-04-08 Thread Rafael E. Ferrero
I see that u use windows... try with these
https://zignar.net/2012/06/17/install-python-on-windows/ first. with
virtualenv you can have more control and diferents versions to try without
any problem.

virtualenv create a virtual machine where you can install django, python,
etc to work with, if somethings goes wrong just delete the virtual machine
and thats its.

Hope to help you


2013/4/5 Olga Zasenko 

> You were right.
> So I fixed the Path. But I'm still getting the same error.
>
>
> On Wednesday, March 27, 2013 7:12:05 PM UTC+2, Tom Evans wrote:
>
>> On Wed, Mar 27, 2013 at 4:39 PM, Olga Zasenko 
>> wrote:
>> > Hi, everybody!
>> > I'm following the instructions on website docs.djangoproject.com and
>> trying
>> > to create my very first Django project.
>> > The only result I get is a confusing error:
>> >
>> > AttributeError: 'module' object has no attribute '_handlerList'.
>> >
>> > My Django version is 1.5, Python - 2.7.3.
>> > I completely deleted and reinstalled Django, but it didn't help.
>> > Maybe the attached screenshot will help.
>> >
>> > Thank you.
>> >
>>
>> I expect that the django-admin.py you are running is not the one you
>> have just installed. Check your PATH and see which is being run.
>>
>> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Rafael E. Ferrero
Claro: (03562) 15514856

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: creating resource with django-tastypie

2013-04-08 Thread psychok7
GOT IT WORKING. It was a problem with the default tastypie read only 
authorization

On Monday, April 8, 2013 12:00:35 PM UTC+1, psychok7 wrote:
>
> it was a quoting problem.. but now i get another error:
>
> HTTP/1.0 401 UNAUTHORIZED
>
> curl --dump-header - -H "Content-Type: application/json" -X POST --data 
> '{"city": "/api/smart/city/35/", "comment": "teste do php", "id": "4", 
> "resource_uri": "/api/smart/rating/4/", "rating": "3","user_id": 
> "/api/smart/auth/user/2/"}' http://localhost:8000/api/smart/rating/ HTTP/1.0 
> 401 UNAUTHORIZED Date: Mon, 08 Apr 2013 10:52:44 GMT Server: WSGIServer/0.1 
> Python/2.7.3 Access-Control-Allow-Origin: * Access-Control-Allow-Methods: 
> POST,GET,OPTIONS,PUT,DELETE Content-Type: text/html; charset=utf-8 
> Access-Control-Allow-Headers: Content-Type,* 
> Access-Control-Allow-Credentials: true
>
> On Monday, April 8, 2013 11:41:11 AM UTC+1, psychok7 wrote:
>>
>> guys i am having problems creating a new resource with django tastypie. i 
>> get the following error:
>>
>> class RatingResource(ModelResource):
>> city = fields.ForeignKey(CityResource, 'city')
>> user_id = fields.ForeignKey(UserResource, 'user')
>> class Meta:
>> queryset = Rating.objects.all()
>> resource_name = 'rating'
>> #authentication = BasicAuthentication()
>> #authorization = DjangoAuthorization()
>>
>> curl --dump-header - -H "Content-Type: application/json" -X POST --data 
>> '{city: "/api/smarturbia/city/35/", comment: "teste do php", id: "4", 
>> resource_uri: "/api/smarturbia/rating/4/", rating: "3",user_id: 
>> "/api/smarturbia/auth/user/2/"}' http://127.0.0.1:8000/api/smarturbia/rating/
>> HTTP/1.0  500 INTERNAL 
>> SERVER ERROR
>> Date: Mon, 08 Apr 2013 10:36:34 GMT
>> Server: WSGIServer/0.1 Python/2.7.3
>> Access-Control-Allow-Origin: *
>> Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
>> Content-Type: application/json
>> Access-Control-Allow-Headers: Content-Type,*
>> Access-Control-Allow-Credentials: true
>>
>> {"error_message": "Expecting property name: line 1 column 1 (char 1)", 
>> "traceback": "Traceback (most recent call last):\n\n  File 
>> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 202, 
>> in wrapper\nresponse = callback(request, *args, **kwargs)\n\n  File 
>> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 440, 
>> in dispatch_list\nreturn self.dispatch('list', request, **kwargs)\n\n  
>> File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 
>> 472, in dispatch\nresponse = method(request, **kwargs)\n\n  File 
>> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 1325, 
>> in post_list\ndeserialized = self.deserialize(request, 
>> request.raw_post_data, format=request.META.get('CONTENT_TYPE', 
>> 'application/json'))\n\n  File 
>> \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 389, 
>> in deserialize\ndeserialized = self._meta.serializer.deserialize(data, 
>> format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n  File 
>> \"/usr/local/lib/python2.7/dist-packages/tastypie/serializers.py\", line 
>> 205, in deserialize\ndeserialized = getattr(self, \"from_%s\" % 
>> desired_format)(content)\n\n  File 
>> \"/usr/local/lib/python2.7/dist-packages/tastypie/serializers.py\", line 
>> 359, in from_json\nreturn simplejson.loads(content)\n\n  File 
>> \"/usr/lib/python2.7/dist-packages/simplejson/__init__.py\", line 413, in 
>> loads\nreturn _default_decoder.decode(s)\n\n  File 
>> \"/usr/lib/python2.7/dist-packages/simplejson/decoder.py\", line 402, in 
>> decode\nobj, end = self.raw_decode(s, idx=_w(s, 0).end())\n\n  File 
>> \"/usr/lib/python2.7/dist-packages/simplejson/decoder.py\", line 418, in 
>> raw_decode\nobj, end = self.scan_once(s, idx)\n\nJSONDecodeError: 
>> Expecting property name: line 1 column 1 (char 1)\n"}
>>
>>
>> any ideas?
>>
>>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




CSRF verification fails on a specific browser

2013-04-08 Thread Bastian
When I try to log in on a Django project that has been working for some time 
with Firefox on Ubuntu I get a CSRF verification failure while with other 
browsers I can log in just fine (Chromium on Ubuntu or Safari on iPad or even 
another Firefox on MacOS). I have checked in the POST that the correct CSRF was 
sent, I have disabled add ons but without success. I tried to force reload, 
forget password, erase cookies but nothing works, I still get the CSRF failure. 
Any idea where I should look?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Creating JSON file

2013-04-08 Thread Nagarajan Dharmar Sitha
saved = sys.stdout
f = file('report.json','a+')
sys.stdout = f
result = []
objects = game_objects.objects.all()
for obj in objects:
dict2 ={}
time = time_stamp.objects.filter(user_id = obj.user_id)
obj_id = obj.object_id
per = performance.objects.filter(user_id = obj.user_id)
pat = pattern.objects.filter(user_id = obj.user_id)
dict2[obj_id]={'color': obj.color, 'speed': obj.speed, 'energy': 
obj.energy }
dict1 = {'user_id' : obj.user_id, 'game_id': obj.game_id}
result.append(dict1)
result.append(dict2)

print json.dumps(result, indent =  4)
sys.stdout = saved

this is my code and out put of the code is:



[
{
"game_id": "000g1",
"user_id": "000u1"
},
{
"000o1": {
"color": "red",
"energy": "300",
"speed": 2
}
},
{
"game_id": "000g2",
"user_id": "000u2"
},
{
"000o2": {
"color": "red",
"energy": "450",
"speed": 6
}
},
{
"game_id": "000g3",
"user_id": "000u3"
},
{
"000o3": {
"color": "red",
"energy": "600",
"speed": 12
}
},
{
"game_id": "000g4",
"user_id": "000u4"
},
{
"000o4": {
"color": "red",
"energy": "750",
"speed": 20
}
},
{
"game_id": "000g5",
"user_id": "000u5"
},
{
"000o5": {
"color": "red",
"energy": "900",
"speed": 30
}
},
{
"game_id": "000g6",
"user_id": "000u6"
},
{
"000o6": {
"color": "red",
"energy": "1050",
"speed": 42
}
},
{
"game_id": "000g7",
"user_id": "000u7"
},
{
"000o7": {
"color": "red",
"energy": "1200",
"speed": 56
}
},
{
"game_id": "000g8",
"user_id": "000u8"
},
{
"000o8": {
"color": "red",
"energy": "1350",
"speed": 72
}
},
{
"game_id": "000g9",
"user_id": "000u9"
},
{
"000o9": {
"color": "red",
"energy": "1500",
"speed": 90
}
}
]


but i want out put like this way:


[
{
"game_id": "000g1",
"user_id": "000u1"
"000o1": {
"color": "red",
"energy": "300",
"speed": 2
}
},
{
"game_id": "000g2",
"user_id": "000u2",
"000o2": {
"color": "red",
"energy": "450",
"speed": 6
}
},
..
.
]


kindly help me 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: New book: Instant Django 1.5 Application Development Starter

2013-04-08 Thread Mauro Rocco
Thank you

On Friday, April 5, 2013 8:27:34 PM UTC+2, megaBos wrote:
>
> good job

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django Generic ForeignKey vs Multiple Foreign Key Fields

2013-04-08 Thread Javier Guerra Giraldez
On Mon, Apr 8, 2013 at 5:34 AM, Arun Prabhakar  wrote:
> more can come in the future

that's reason enough to use Generic relations


--
Javier

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django Generic ForeignKey vs Multiple Foreign Key Fields

2013-04-08 Thread Javier Guerra Giraldez
On Mon, Apr 8, 2013 at 8:43 AM, Javier Guerra Giraldez
 wrote:
> On Mon, Apr 8, 2013 at 5:34 AM, Arun Prabhakar  wrote:
>> more can come in the future
>
> that's reason enough to use Generic relations


(of course, much better would be if you can refactor your data
representation so you can go with a fixed set of tables)

--
Javier

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Creating JSON file

2013-04-08 Thread Seth Gordon
You want to output a list of one dict per object, and you want that dict to
contain another dict inside it. So you don’t need dict2. Instead

f = file('report.json','a+')
sys.stdout = f
result = []
objects = game_objects.objects.all()
for obj in objects:
time = time_stamp.objects.filter(user_id = obj.user_id)
obj_id = obj.object_id
per = performance.objects.filter(user_id = obj.user_id)
pat = pattern.objects.filter(user_id = obj.user_id)
dict1 = {'user_id' : obj.user_id, 'game_id': obj.game_id}
dict1[obj_id]={'color': obj.color, 'speed': obj.speed, 'energy':
obj.energy }
result.append(dict1)


On Mon, Apr 8, 2013 at 8:33 AM, Nagarajan Dharmar Sitha <
nagarajan.dharmarsi...@gmail.com> wrote:

> saved = sys.stdout
> f = file('report.json','a+')
> sys.stdout = f
> result = []
> objects = game_objects.objects.all()
> for obj in objects:
> dict2 ={}
> time = time_stamp.objects.filter(user_id = obj.user_id)
> obj_id = obj.object_id
> per = performance.objects.filter(user_id = obj.user_id)
> pat = pattern.objects.filter(user_id = obj.user_id)
> dict2[obj_id]={'color': obj.color, 'speed': obj.speed, 'energy':
> obj.energy }
> dict1 = {'user_id' : obj.user_id, 'game_id': obj.game_id}
> result.append(dict1)
> result.append(dict2)
>
> print json.dumps(result, indent =  4)
> sys.stdout = saved
>
> this is my code and out put of the code is:
>
>
>
> [
> {
> "game_id": "000g1",
> "user_id": "000u1"
> },
> {
> "000o1": {
> "color": "red",
> "energy": "300",
> "speed": 2
> }
> },
> {
> "game_id": "000g2",
> "user_id": "000u2"
> },
> {
> "000o2": {
> "color": "red",
> "energy": "450",
> "speed": 6
> }
> },
> {
> "game_id": "000g3",
> "user_id": "000u3"
> },
> {
> "000o3": {
> "color": "red",
> "energy": "600",
> "speed": 12
> }
> },
> {
> "game_id": "000g4",
> "user_id": "000u4"
> },
> {
> "000o4": {
> "color": "red",
> "energy": "750",
> "speed": 20
> }
> },
> {
> "game_id": "000g5",
> "user_id": "000u5"
> },
> {
> "000o5": {
> "color": "red",
> "energy": "900",
> "speed": 30
> }
> },
> {
> "game_id": "000g6",
> "user_id": "000u6"
> },
> {
> "000o6": {
> "color": "red",
> "energy": "1050",
> "speed": 42
> }
> },
> {
> "game_id": "000g7",
> "user_id": "000u7"
> },
> {
> "000o7": {
> "color": "red",
> "energy": "1200",
> "speed": 56
> }
> },
> {
> "game_id": "000g8",
> "user_id": "000u8"
> },
> {
> "000o8": {
> "color": "red",
> "energy": "1350",
> "speed": 72
> }
> },
> {
> "game_id": "000g9",
> "user_id": "000u9"
> },
> {
> "000o9": {
> "color": "red",
> "energy": "1500",
> "speed": 90
> }
> }
> ]
>
>
> but i want out put like this way:
>
>
> [
> {
> "game_id": "000g1",
> "user_id": "000u1"
> "000o1": {
> "color": "red",
> "energy": "300",
> "speed": 2
> }
> },
> {
> "game_id": "000g2",
> "user_id": "000u2",
> "000o2": {
> "color": "red",
> "energy": "450",
> "speed": 6
> }
> },
> ..
> .
> ]
>
>
> kindly help me 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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




urgent - how do I tell django to relax required password?

2013-04-08 Thread frocco
on registration, login django is asking for uppercase and special chars for 
password.
how do I tell django to allow basic passwords?

My site is live and I am having issues
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Why is a username required for a User?

2013-04-08 Thread Cody Scott
To create a User object you need to have a unique username.

I would like to use an email and a password to identify users, since an 
email is already required for my site's functionality.

It seems silly for a framework so restrict you.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Why is a username required for a User?

2013-04-08 Thread Anderson
Hey Cody are using django 1.5?


On Mon, Apr 8, 2013 at 9:09 AM, Cody Scott  wrote:

> To create a User object you need to have a unique username.
>
> I would like to use an email and a password to identify users, since an
> email is already required for my site's functionality.
>
> It seems silly for a framework so restrict you.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Anderson Dias Borges
Senior Analyst Developer

Tu cumprirás o desejo do meu coração se eu Te buscar...
I can't see but I'll take my chances
To hear You call my name

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: urgent - how do I tell django to relax required password?

2013-04-08 Thread Larry Martell
On Mon, Apr 8, 2013 at 9:02 AM, frocco  wrote:
> on registration, login django is asking for uppercase and special chars for
> password.
> how do I tell django to allow basic passwords?
>
> My site is live and I am having issues


This may help you: https://github.com/dstufft/django-passwords

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [SPAM] Implementing User login expiration

2013-04-08 Thread John DeRosa
On Apr 5, 2013, at 5:33 PM, Nikolas Stevenson-Molnar  
wrote:

> How about creating request middleware to sign out deactivated users?
> Something like:
> 
> if request.user.profile.expired:
>logout(request)
> 
> If you're concerned about the extra database hit per request, then maybe
> cache the expiration?
> 
> expire_date = cache.get("%d_expire" % request.user.id)
> if not expire_date:
>expire_date = request.user.profile.expire_date
>cache.set(...)
> if expire date < now()
>logout(request)
> 
> _Nik

Great idea! Thank you!

John

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: urgent - how do I tell django to relax required password?

2013-04-08 Thread frocco
Thanks

Resolved

On Monday, April 8, 2013 11:18:32 AM UTC-4, larry@gmail.com wrote:
>
> On Mon, Apr 8, 2013 at 9:02 AM, frocco > 
> wrote: 
> > on registration, login django is asking for uppercase and special chars 
> for 
> > password. 
> > how do I tell django to allow basic passwords? 
> > 
> > My site is live and I am having issues 
>
>
> This may help you: https://github.com/dstufft/django-passwords 
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Why is a username required for a User?

2013-04-08 Thread Cody Scott
Yes I am using Django 1.5

On Monday, 8 April 2013 11:11:57 UTC-4, Anderson Borges wrote:
>
> Hey Cody are using django 1.5?
>
>
> On Mon, Apr 8, 2013 at 9:09 AM, Cody Scott 
> > wrote:
>
>> To create a User object you need to have a unique username.
>>
>> I would like to use an email and a password to identify users, since an 
>> email is already required for my site's functionality.
>>
>> It seems silly for a framework so restrict you.
>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Anderson Dias Borges
> Senior Analyst Developer
>
> Tu cumprirás o desejo do meu coração se eu Te buscar...
> I can't see but I'll take my chances
> To hear You call my name 
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Why is a username required for a User?

2013-04-08 Thread Anderson
You can use BaseUserManager, AbstractBaseUser,PermissionsMixin.
here is a exemple:

from django.db import models
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin,
BaseUserManager
from django.confimport settings


class MyUserManager(BaseUserManager):
def create_user(self, email, password=None):
if not email:
raise ValueError('Users must have an email address')

user = self.model(
email=MyUserManager.normalize_email(email),
)
user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, password):
user = self.create_user(email,
password=password
)
user.is_admin = True
user.save(using=self._db)
return user

class Users(AbstractBaseUser,PermissionsMixin):
email = models.EmailField(verbose_name='email address',
max_length=255,unique=True,db_index=True,)
name  = models.CharField(verbose_name='Name',
max_length=50,blank=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
is_customer = models.BooleanField(default=False)
datecreated = models.DateField(auto_now=True)

objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name']

def get_full_name(self):
return self.email

def get_short_name(self):
return self.email

def __unicode__(self):
return self.email

@property
def is_staff(self):
return self.is_admin



Now in your settings you have to add : AUTH_USER_MODEL = 'auth.Users'






If you want change in ADMIN here the code


from django.contrib import admin
from django import forms
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField

from models import Users

class UserCreationForm(forms.ModelForm):
password1 = forms.CharField(label='Password',
widget=forms.PasswordInput)
password2 = forms.CharField(label='Password confirmation',
widget=forms.PasswordInput)

class Meta:
model = Users

def clean_password2(self):
# Check that the two password entries match
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Passwords don't match")
return password2

def save(self, commit=True):
# Save the provided password in hashed format
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user

class UserChangeForm(forms.ModelForm):
password = ReadOnlyPasswordHashField()
class Meta:
model = Users

def clean_password(self):
return self.initial["password"]

class MyUserAdmin(UserAdmin):
form = UserChangeForm
add_form = UserCreationForm

list_display = ('email', 'is_admin')
list_filter = ('is_admin',)
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Permissions', {'fields':
('is_admin','groups','user_permissions')}),
('Important dates', {'fields': ('last_login',)}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'password1', 'password2')}
),
)
search_fields = ('email',)
ordering = ('email',)
filter_horizontal = ()

admin.site.register(Users, MyUserAdmin)





On Mon, Apr 8, 2013 at 9:49 AM, Cody Scott  wrote:

> Yes I am using Django 1.5
>
>
> On Monday, 8 April 2013 11:11:57 UTC-4, Anderson Borges wrote:
>
>> Hey Cody are using django 1.5?
>>
>>
>> On Mon, Apr 8, 2013 at 9:09 AM, Cody Scott  wrote:
>>
>>> To create a User object you need to have a unique username.
>>>
>>> I would like to use an email and a password to identify users, since an
>>> email is already required for my site's functionality.
>>>
>>> It seems silly for a framework so restrict you.
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users?hl=en
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out
>>> .
>>>
>>>
>>>
>>
>>
>>
>> --
>> Anderson Dias Borges
>> Senior Analyst Developer
>>
>> Tu cumprirás o desejo do meu coração se eu Te buscar...
>> I can't see but I'll take my chances
>> To hear You call my name
>>
>  --
> You receiv

Re: Why is a username required for a User?

2013-04-08 Thread Tom Evans
On Mon, Apr 8, 2013 at 4:49 PM, Cody Scott  wrote:
> Yes I am using Django 1.5

In 1.5, you can fully customise what fields your User class has. Full
notes in the docs:

https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#auth-custom-user

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




How to rename objects (Urgent)

2013-04-08 Thread Giorgos Kontogiorgakis
Hi there guys!I have an answer about renaming objects on my 
webinterface.For example i have a table named "Map" and i have many obejcts 
in there(Map object,Map object,Map object,Map object,Map object,Map object) 
How is it possible to rename them?I mean i want to have something like (Map 
Asia,Map Europe,Map America,Map Africa and so on) for every object to give 
him a different name.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Understanding UpdateView with forms and formsets

2013-04-08 Thread Nora Olsen
Hi,

I'm a new user to Django. 

I'm trying to understand how does an UpdateView works when during a POST. 
Is there some state carried between the GET and POST, because I don't see 
the pk in the form. How does the form save() knows that it should be 
updating instead of inserting?

The reason I'm asking is because I am having trouble trying to save a 
formset that is used in a view together with the main form. I posted the 
question on stackoverflow: 
http://stackoverflow.com/questions/15877199/using-formset-with-contenttype

I am trying to save Item with multiple Pictures in a single form.

I can easily save the item form in the Post method of the view but I can't 
save the formsets without the pk. In my template, I have the following:


{% for field in form %}
# do something
{% endfor %}

{{ picture_formset.management_form }}
{% for form in picture_formset.forms %}
# do something
{% endfor %}




And my view:


class ItemUpdateView(UpdateView):

form_class = ItemCreateForm
template_name = 'item/new.html'
model = Item
success_url = '/items/'
def get_context_data(self, **kwargs):
context = super(ItemUpdateView, self).get_context_data(**kwargs)
item = context['object']
# Dont' create any extra forms when showing an update view
PictureFormSet = formset_factory(PictureForm, extra=0)
return {'form': kwargs['form'],
'picture_formset': UploadFormSet(initial = [ 
model_to_dict(a) for pic in item.pictures.all()])}
def post(self, request, *args, **kwargs):
   self.object = self.get_object()
   item_form = ItemCreateForm(request.POST, instance=self.object)
   if item_form.is_valid():
   item = item_form.save(commit=False)
   item.save()
   # How do I update the pictures? 


I did manage to solve this by adding the pk as a HiddenWidget and obtaining 
the Picture model before updating the keys/values and saving it.

But I had to create 2 type of forms: with and without the pk for the 
CreateView and UpdateView.

Is this the correct approach? 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to rename objects (Urgent)

2013-04-08 Thread Serdar Dalgic
On Mon, Apr 8, 2013 at 7:26 PM, Giorgos Kontogiorgakis
 wrote:
> Hi there guys!I have an answer about renaming objects on my webinterface.For
> example i have a table named "Map" and i have many obejcts in there(Map
> object,Map object,Map object,Map object,Map object,Map object) How is it
> possible to rename them?I mean i want to have something like (Map Asia,Map
> Europe,Map America,Map Africa and so on) for every object to give him a
> different name.
>

Hi Giorgos;

I assume you mean django admin by webinterface. If I understood you
right; In your models, if you define a __unicode__ function, you can
get what you want. Just a plain example:

Class Map(models.Model):
name = models.CharField(max_length=64)
..
..
def __unicode__(self):
return self.name

Assuming you create maps like this:

asia=Map(name="Map Asia")
asia.save()

For more details, take a look at
https://docs.djangoproject.com/en/dev/ref/models/instances/#unicode

-- 
- Serdar Dalgıç 
FLOSS Developer, Life & Nature Hacker
twitter: https://twitter.com/serdaroncode

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Understanding UpdateView with forms and formsets

2013-04-08 Thread Rainy




On Monday, April 8, 2013 12:22:34 PM UTC-4, Nora Olsen wrote:
>
> Hi,
>
> I'm a new user to Django. 
>
> I'm trying to understand how does an UpdateView works when during a POST. 
> Is there some state carried between the GET and POST, because I don't see 
> the pk in the form. How does the form save() knows that it should be 
> updating instead of inserting?
>
> The reason I'm asking is because I am having trouble trying to save a 
> formset that is used in a view together with the main form. I posted the 
> question on stackoverflow: 
> http://stackoverflow.com/questions/15877199/using-formset-with-contenttype
>
> I am trying to save Item with multiple Pictures in a single form.
>
> I can easily save the item form in the Post method of the view but I can't 
> save the formsets without the pk. In my template, I have the following:
>
> 
> {% for field in form %}
> # do something
> {% endfor %}
>
> {{ picture_formset.management_form }}
> {% for form in picture_formset.forms %}
> # do something
> {% endfor %}
> 
> 
>
>
> And my view:
>
>
> class ItemUpdateView(UpdateView):
>
> form_class = ItemCreateForm
> template_name = 'item/new.html'
> model = Item
> success_url = '/items/'
> def get_context_data(self, **kwargs):
> context = super(ItemUpdateView, self).get_context_data(**kwargs)
> item = context['object']
> # Dont' create any extra forms when showing an update view
> PictureFormSet = formset_factory(PictureForm, extra=0)
> return {'form': kwargs['form'],
> 'picture_formset': UploadFormSet(initial = [ 
> model_to_dict(a) for pic in item.pictures.all()])}
> def post(self, request, *args, **kwargs):
>self.object = self.get_object()
>item_form = ItemCreateForm(request.POST, instance=self.object)
>if item_form.is_valid():
>item = item_form.save(commit=False)
>item.save()
># How do I update the pictures? 
>
>
> I did manage to solve this by adding the pk as a HiddenWidget and 
> obtaining the Picture model before updating the keys/values and saving it.
>
> But I had to create 2 type of forms: with and without the pk for the 
> CreateView and UpdateView.
>
> Is this the correct approach? 
>


Hi Nora, the way it works is that it uses get_object() method to load the 
object; at the top of post() method,
it has the line: self.object = self.get_object().

If you need to use modelformset together with a form or modelform in one 
view, you might
want to look at my mcbv library; it has both a modelformset CBV and also 
allows to easily
combine different types of views together.

The portfolio tutorial has a good examples of doing just that: 
http://lightbird.net/dbe2/portfolio.html

mcbv library itself currently lives here: https://github.com/akulakov/django

 -ak

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Creating a admin-field, containing checkboxes. The data of this fields is stored in the string format

2013-04-08 Thread Sam Solomon
Not sure exactly what the issue is, but this may be handy (either as a 
replacement or as an example of doing something somewhat similar):

https://github.com/disqus/django-bitfield

I believe on most machines the maximum is 63 "flags" though so you will 
likely only be able to use it as an example of doing something very 
similar, unless you split it into 7 days of 24 hours which may be more 
database efficient (7 BigInts is probably easier for a database to 
store/query than a 168 char string). One interesting trick for going this 
route is you could query for if one of the days is > 0 and if it is at 
least one item is checked instead of having to do string comparisons.

On Friday, April 5, 2013 4:07:02 AM UTC-7, Дмитрий Кольдяев wrote:
>
> I`m trying to create form field for Django admin backend In database it 
> should be CharField field, contains "0" and "1" values with 24*7 length. In 
> admin panels I want to see them as 7 fields with 24 checkboxes each. If 
> checkbox is checked coressponding position of the string sets to "1", else 
> "0".
>
> model.py
>
> from django.db import modelsfrom places.widgets import *from places.fields 
> import *
> class Place(models.Model):
> …
> time =  HoursWorkByWeekField()
> …
>
> fields.py
>
> from django.forms import fieldsfrom django.db import models
> from places.widgets import HoursWorkByWeekWidget
> class HoursWorkByWeekField(models.CharField):
> widget = HoursWorkByWeekWidget
>
> def __init__(self):
> super(HoursWorkByWeekField, self).__init__(max_length=24*7, 
> min_length=24*7)
>
> def to_python(self, value):
> return list(value)
>
> def get_db_prep_value(self, value):
> result = []
> for i in range(24*7):
> if value[i] :
> result += ['1']
> else :
> result += ['0']
> return ''.join(result)
>
> widgets.py
>
> from django.forms import widgets
> class HoursWorkByDayWidget(widgets.CheckboxSelectMultiple):
> def render(self, name, attrs=None):
> choices = range(0,24,1)
> return widgets.CheckboxSelectMultiple.render(self, name, attrs, 
> choices)
> class HoursWorkByWeekWidget(widgets.MultiWidget):
> def __init__(self, attrs=None):
> widgets = (
> HoursWorkByDayWidget(),
> HoursWorkByDayWidget(),
> HoursWorkByDayWidget(),
> HoursWorkByDayWidget(),
> HoursWorkByDayWidget(),
> HoursWorkByDayWidget(),
> HoursWorkByDayWidget(),
> )
> super(HoursWorkByWeekWidget, self).__init__(widgets, attrs)
>
> When i try syncdb i have error:
>
> TypeError: Error when calling the metaclass bases unhashable type: 'dict'
>
> What am I doing wrong? How to organize code?
> Many thanks in advance
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Understanding UpdateView with forms and formsets

2013-04-08 Thread Rainy
Sorry, I answered before reading your full message. It looks like you 
understand post loads the object in get_object(). I just want to add
that combined create/update can be done in different ways; I have
an implementation in mcbv.edit module but I'm not sure if it's the
best approach in all cases.

I don't think having two forms is a problem,
you can have one form for update and then inherit and modify as
needed for create.  -ak

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to rename objects (Urgent)

2013-04-08 Thread Giorgos Kontogiorgakis
Hi Serdar!

Yeah,i mean django admin by webinterface!I didn't created the spessific 
table,i already had a legacy database running.For example i have the next 
code for 1 of my tables in models.py:

class Links(models.Model):
interfacein = models.CharField(max_length=20L, db_column='InterfaceIn') 
interfaceout = models.CharField(max_length=20L, 
db_column='InterfaceOut') 
capacity = models.FloatField(null=True, db_column='Capacity', 
blank=True) 
delay = models.FloatField(null=True, db_column='Delay', blank=True)
class Meta:
db_table = 'Links'

So,on my interface when i click on the "Links" i can see the objects that 
are into my database,all of them have the name "Links objects" and then 
when i click on 1 of them THEN i can see my fields.I don't want to change 
the name on any field or something but the name of "Link objects"

Links-->Links object(multiple times)[i want to change 
that]-->interfacein,interfaceout,capacity,delay(with their values)
Thx for ur time and i hope you can help me :))

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Accessing list of dictionaries in jQuery

2013-04-08 Thread Larry Martell
I am passing a list of dictionaries to my template. In the template
language I can do this and it works as expected:

{% for row in images %}





{% endfor %}

But I need to process this data in jQuery. If I pass images into a
function like this:

my_func({{ images }});

I get a syntax error, 'unexpected token &'

And if I pass it in like this:

my_func("{{ images }}");

It is received in the function as a character string, not as a list of
dictionaries. How can I pass this to my function and have it be
received as the list of dictionaries that it is?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Accessing list of dictionaries in jQuery

2013-04-08 Thread Nikolas Stevenson-Molnar
Injecting data into a template can be tricky. I would recommend doing
two things:

1) Serialize your data to JSON in your view first using Python's json
module. Something like this:
>>> images_as_json = json.dumps(images)

2) Rather than trying to inject it directly into JavaScript, which can
cause encoding-related issues, dump your JSON-formatted string into a
hidden node on page, then read it out and parse it into a JS object. So,
for example:

{{ images_as_json }}

Deploying: Desktop to server

2013-04-08 Thread Tim Johnson
FYI - I'm new to django, but have been doing web programming since
'96 and python since '03.

I intend to put together a test site on my desktop and push it to a
remote server. I will be the only user making changes to this site.

Thus I presume that it is OK to push the database as well.

Am I correct?

And URLs to discussion and instructions on deployment are invited.
:)

thanks
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Accessing list of dictionaries in jQuery

2013-04-08 Thread Larry Martell
I appreciate the suggestion, but using a hidden field sounds very
kludgy. Is there no other way?

On Mon, Apr 8, 2013 at 6:01 PM, Nikolas Stevenson-Molnar
 wrote:
> Injecting data into a template can be tricky. I would recommend doing
> two things:
>
> 1) Serialize your data to JSON in your view first using Python's json
> module. Something like this:
 images_as_json = json.dumps(images)
>
> 2) Rather than trying to inject it directly into JavaScript, which can
> cause encoding-related issues, dump your JSON-formatted string into a
> hidden node on page, then read it out and parse it into a JS object. So,
> for example:
>
> {{ images_as_json }}
> 

Re: Deploying: Desktop to server

2013-04-08 Thread Shawn Milochik
It should be fine, unless you're using encrypted fields, using the
SECRET_KEY setting as the key, and have a different key in production.

Of course, if you want to keep the databases in sync after that, that's
another issue.
On Apr 8, 2013 5:09 PM, "Tim Johnson"  wrote:

> FYI - I'm new to django, but have been doing web programming since
> '96 and python since '03.
>
> I intend to put together a test site on my desktop and push it to a
> remote server. I will be the only user making changes to this site.
>
> Thus I presume that it is OK to push the database as well.
>
> Am I correct?
>
> And URLs to discussion and instructions on deployment are invited.
> :)
>
> thanks
> --
> Tim
> tim at tee jay forty nine dot com or akwebsoft dot com
> http://www.akwebsoft.com
>
> --
> 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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Accessing list of dictionaries in jQuery

2013-04-08 Thread Nikolas Stevenson-Molnar
Injecting data into client code is bound the be kludgy any way you slice
it. The reason for passing it through a hidden element has to do with
correct escaping of characters. Consider the following:

$.parseJSON("{{ images_as_json }}");

and lets say this is rendered as:

$.parseJSON("{foo: "bar"}");

See the problem? Yes, you could use single quotes, as in
$.parseJSON('{foo: "bar"}') but if any of your serialized data contain
single quotes (or an apostrophe), then you're back to the same problem.
You could URL-encode your serialized JSON string and then pass it
through decodeURIComponent() in JS, but I've found that to not always be
reliable. Injecting the JSON string into an element removes all of those
problems. And IMHO it's /less/ kludgy, as your data isn't being injected
directly into your client-side code; rather, your code is "loading" the
data from a node in the DOM.

Others may have come up with other ways around this (I suspect many just
load the data asynchronously), but this is the most reliable method I've
come up with to get data into a client-side script without an
asynchronous call.

_Nik

On 4/8/2013 5:24 PM, Larry Martell wrote:
> I appreciate the suggestion, but using a hidden field sounds very
> kludgy. Is there no other way?
>
> On Mon, Apr 8, 2013 at 6:01 PM, Nikolas Stevenson-Molnar
>  wrote:
>> Injecting data into a template can be tricky. I would recommend doing
>> two things:
>>
>> 1) Serialize your data to JSON in your view first using Python's json
>> module. Something like this:
> images_as_json = json.dumps(images)
>> 2) Rather than trying to inject it directly into JavaScript, which can
>> cause encoding-related issues, dump your JSON-formatted string into a
>> hidden node on page, then read it out and parse it into a JS object. So,
>> for example:
>>
>> {{ images_as_json }}
>> 

Re: Deploying: Desktop to server

2013-04-08 Thread Tim Johnson
* Shawn Milochik  [130408 16:41]:
> It should be fine, unless you're using encrypted fields, using the
> SECRET_KEY setting as the key, and have a different key in production.
> 
> Of course, if you want to keep the databases in sync after that, that's
> another issue.
  Understood.
  Thanks.
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




cleaned_data returning empty in formsets

2013-04-08 Thread Nora Olsen

The following snippet is returning an empty dictionary for the 2nd form:

 

> dct = {'form-0-attachment': u'',
>  'form-0-id': u'1',
>  'form-0-name': u'1',
>  'form-1-attachment': u'',
>  'form-1-id': u'2',
>  'form-1-name': u'2',
>  'form-INITIAL_FORMS': u'1',
>  'form-MAX_NUM_FORMS': u'1000',
>  'form-TOTAL_FORMS': 2}
> PictureFormSet = formset_factory(PictureForm)
> picture_formset = PictureFormSet(dct, None,
>  initial = [ model_to_dict(a) for a in 
> Picture.objects.filter(pk__in = [1,2])])
> for form in picture_formset.forms:
> if form.is_valid():
> print form.cleaned_data
> print '---'
> Output:
> {'id': 1, 'name': u'1', 'attachment': None}
> ---
> {}
> ---


How does initial work with data= in a formset?  Without the initial, there 
will be cleaned data for the 2nd form.

I'm trying to use self.changed_data in my form to determine whether which 
value has changed.




-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: cleaned_data returning empty in formsets

2013-04-08 Thread Nora Olsen
Just found the culprit:

'form-INITIAL_FORMS': u'1', it must be 2. 


On Tuesday, April 9, 2013 1:09:10 PM UTC+8, Nora Olsen wrote:
>
>
> The following snippet is returning an empty dictionary for the 2nd form:
>
>  
>
>> dct = {'form-0-attachment': u'',
>>  'form-0-id': u'1',
>>  'form-0-name': u'1',
>>  'form-1-attachment': u'',
>>  'form-1-id': u'2',
>>  'form-1-name': u'2',
>>  'form-INITIAL_FORMS': u'1',
>>  'form-MAX_NUM_FORMS': u'1000',
>>  'form-TOTAL_FORMS': 2}
>> PictureFormSet = formset_factory(PictureForm)
>> picture_formset = PictureFormSet(dct, None,
>>  initial = [ model_to_dict(a) for a in 
>> Picture.objects.filter(pk__in = [1,2])])
>> for form in picture_formset.forms:
>> if form.is_valid():
>> print form.cleaned_data
>> print '---'
>> Output:
>> {'id': 1, 'name': u'1', 'attachment': None}
>> ---
>> {}
>> ---
>
>
> How does initial work with data= in a formset?  Without the initial, there 
> will be cleaned data for the 2nd form.
>
> I'm trying to use self.changed_data in my form to determine whether which 
> value has changed.
>
>
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.