Re: (Another) Authentication Question

2016-04-23 Thread knbk
Hi Jason,

Your form inputs in the login form are missing a name attribute, so the 
data you input into the form won't be sent to the server on submit. Without 
any data, the form is invalid, and is redisplayed. If you add the correct 
name attribute to the input tags, your form should work as expected.

Marten

On Thursday, April 21, 2016 at 1:25:53 PM UTC+2, Jason Wolosonovich wrote:
>
> Hello All, 
>
> I'm completely new to Django and I've been following along with the 
> excellent video series from CodingEntrepreneurs on YouTube and applying 
> what I can to my project. I'm stuck on the authentication process. I don't 
> believe that the request is being passed to my template correctly because 
> in the template, I'm checking for authentication and if present, I'm 
> displaying the content (or trying to anyway) and if not, I'm rendering a 
> message informing the user that they're not logged in. 
>
> my app is title 'theapp' and I have a single view called 'index' that is 
> decorated with '@login_required' and redirecting to '/accounts/login'. I 
> have two users, both of which I created and activated. When I enter 
> credentials, I'm redirected right back to the login page. My view is pretty 
> simple: 
>
>
> def index(request): 
> return render(request, 'index.html', {}) 
>
>
> If my project is called 'thesite', in 'thesite/urls.py' I have these 
> patterns: 
>
>
>
> urlpatterns = [ 
>
> url(r'^theapp/', 
> include('theapp.urls')), 
>
> url(r'^admin/', 
> admin.site.urls), 
>
> url(r'^login/$', 
> 'django.contrib.auth.views.login', 
> {'template_name': 'login.html'}, 
> name='login') 
>
> ] 
>
>
>
>
>
>
>
> In my app urls ('theapp/urls.py') I have this pattern: 
>
>
>
>
>
>
> urlpatterns = [ 
> url(r'^$', 
> views.index, 
> name='index'), 
>
> ] 
>
>
>
>
>
>
> My 'base' form is like so: 
>
>
>
>
>
>
> http://getbootstrap.com/favicon.ico";> 
>
> Login 
>
>  
> http://getbootstrap.com/dist/css/bootstrap.min.css"; 
> rel="stylesheet"> 
>
>  
> http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css"; 
> rel="stylesheet"> 
>
>  
> http://getbootstrap.com/examples/signin/signin.css"; 
> rel="stylesheet"> 
>
>  
>  
>
>
> 

Re: Can not read request.body from a POST request

2016-04-23 Thread Daniel Roseman
On Wednesday, 20 April 2016 21:29:09 UTC+1, Mihai Corciu wrote:
>
> Is there a method to access request.body from a POST request in Django, 
> without disabling 'django.middleware.csrf.CsrfViewMiddleware' ?
>
> CsrfViewMiddleware is causing:
>
> Exception Type: RawPostDataException
> Exception Value: You cannot access body after reading from request's 
> data stream
>
> which means request.body is impossible to acces without disabling 
> CsrfViewMiddleware.
>


This should not be happening. CsrfViewMiddleware is enabled by default and 
does not interfere with reading request.body. Please post the full 
traceback.
--
Daniel.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/46923ca1-1752-474e-a607-708dfd7a44d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ValueError: cannot reindex from a duplicate axis

2016-04-23 Thread Chen
http://stackoverflow.com/questions/36809762/valueerror-cannot-reindex-from-a-duplicate-axis-while-using-pivot-table

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1ca66da6-8c31-4185-ba37-131733927a3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Help with defining Models for ManyToMany and OneToMany relationships...

2016-04-23 Thread Bruce Whealton
Hello all,
  So, I setup django in a virtualenv on my Ubuntu environment.  I 
was reading the docs and thought I had things right 
for creating the 3 models I wanted with this application. I am using 
Postgresql.  I have the Postgresql driver for Python/Django installed
in the virtualenv.  It is a "Contacts" app.  
First question: Do django model fields default to required unless you use 
blank=True, null=True?
Many of my fields, I want to have optional.

I have a class called Contact, a class called Organization and a class 
called Connection.  
I wanted to use the Organization as a foreign key on the Contact model.  I 
could have more than one contact from
an Organization.  The Connection model is inspired by the Google Plus idea 
of "Circles" - e.g. friends,
family, following, etc.   So, this would be a many-to-many relationship.  

My problems are (1) I cannot create connections without specifying a 
contact.  
(2) If I was adding a contact using the admin interface, how do I allow no 
value for that foreign field
or allow for some kind of ajax type of text completion?  If a person is 
family or friend, I may not need
to list an Organization for them.
(3) I would like to support multiple connection types - e.g. following, 
employer, etc.

So, here is my apps models.py file:


from django.db import models


class Contact(models.Model):
name = models.CharField(max_length=40)
Organization = models.CharField(max_length=50)
street_line1 = models.CharField("Street Line 1", max_length=50)
street_line2 = models.CharField("Street Line 2", max_length=50)
city = models.CharField(max_length=40)
state = models.CharField(max_length=40)
zipcode = models.CharField(max_length=20, blank=True, null=True)
phone1 = models.CharField(max_length=20)
phone2 = models.CharField(max_length=20)
email = models.EmailField(max_length=60)


class Organization(models.Model):
name = models.CharField(max_length=60)
street_line1 = models.CharField("Street Line 1", max_length=50)
street_line2 = models.CharField("Street Line 2", max_length=50)
city = models.CharField(max_length=40)
state = models.CharField(max_length=40)
zipcode = models.CharField(max_length=20, blank=True, null=True,)
phone = models.CharField(max_length=20)
email = models.EmailField(max_length=60)
website = models.URLField(max_length=90)
contact_name = models.ForeignKey(Contact, on_delete=models.CASCADE)


class Connection(models.Model):
type = models.CharField(max_length=60)
contact_name = models.ManyToManyField(Contact)   

>>>
Thanks in advance for any suggestions,
Bruce 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/caede40b-640c-4e8d-997d-b76c62922c19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can not read request.body from a POST request

2016-04-23 Thread Vijay Khemlani
Yeah, I was wrong, I actually use request.body in my code without problem
with the default middlewares enabled.

On Sat, Apr 23, 2016 at 11:00 AM, Daniel Roseman 
wrote:

> On Wednesday, 20 April 2016 21:29:09 UTC+1, Mihai Corciu wrote:
>>
>> Is there a method to access request.body from a POST request in Django,
>> without disabling 'django.middleware.csrf.CsrfViewMiddleware' ?
>>
>> CsrfViewMiddleware is causing:
>>
>> Exception Type: RawPostDataException
>> Exception Value: You cannot access body after reading from request's
>> data stream
>>
>> which means request.body is impossible to acces without disabling
>> CsrfViewMiddleware.
>>
>
>
> This should not be happening. CsrfViewMiddleware is enabled by default and
> does not interfere with reading request.body. Please post the full
> traceback.
> --
> Daniel.
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/46923ca1-1752-474e-a607-708dfd7a44d3%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: scarico() got an unexpected keyword argument 'string'

2016-04-23 Thread Daniel Roseman
On Friday, 22 April 2016 15:41:29 UTC+1, Steven Crockett wrote:
>
>
> def scarico(request, data):
> print(data)
>
> You are expecting two positional arguments, and no keyword arguments.
> To properly capture your keyword argument named "my_string" your 
> definition should be written as: 
>
> def scarico(request, my_string=''):
> print(my_string)
>


Python doesn't make the distinction you imply between positional and 
keyword arguments in function definitions. It is always possible to pass an 
argument as a keyword, even if it is defined without a default. `def 
scarico(request, my_string)` is the correct signature here.
--
Daniel

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/27852d25-db39-4777-b55a-2ce17a253efa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[django1.9] Url template tag, dotted path and decorator

2016-04-23 Thread François Magimel
Hi!

I'm facing an issue reversing a dotted path with django 1.9.4. Here are more 
details.

I pass a dotted path to the django template tag "url":
"{% url 'my.app.view.func' arg %}"
And the function "my.app.view.func" has a decorator which is using "arg". My 
problem is : when displaying my template, I get a NoReverseMatch error.
But I don't have any error:
  - when I use the name of the url (defined in my urls.py file) or
  - when I use the dotted path and remove my (simple) decorator.

I know that passing a dotted path to url is deprecated since django 1.8 [0][1], 
but not removed yet. So, I think there is something wrong with dotted path and 
decorators, but I can't find what…

PS: my decorator only redirects to another view…

Thanks,
François


[0] 
https://docs.djangoproject.com/en/1.8/releases/1.8/#passing-a-dotted-path-to-reverse-and-url
[1] https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#url

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/785ab0e5-25a8-99b9-2106-f5c5d6a09880%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

2016-04-23 Thread Chris Seberino
Why redirects to foo.com/?next=/some/folder show up as 
foo.com/?next=%2Fsome%2Ffolder in browser?  (i.e. how remove the %2F's? )

Is there a function I can call on URLs built in a view to avoid that?

cs

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/137f689f-306d-4528-82cd-03413b747f2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django not adding / to end of URLS and since urls.py expects /, I now get 404s. How fix?

2016-04-23 Thread Chris Seberino
I am trying to be consistent and make urls.py expect / after every url.

The problem is Django isn't automatically adding / at the end and so now
I get 404s when I try to access my web pages.  

How fix?

Thanks!

Chris

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff0af6d2-e658-4741-bef7-0f700db2b454%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django not adding / to end of URLS and since urls.py expects /, I now get 404s. How fix?

2016-04-23 Thread Michal Petrucha
On Sat, Apr 23, 2016 at 11:50:05AM -0700, Chris Seberino wrote:
> I am trying to be consistent and make urls.py expect / after every url.
> 
> The problem is Django isn't automatically adding / at the end and so now
> I get 404s when I try to access my web pages.  
> 
> How fix?

https://docs.djangoproject.com/en/1.9/ref/settings/#append-slash

But this shouldn't happen to you with URLs from within your
application, as long as you use the url template tag, and reverse for
redirects – those will generate correct URLs for you, including the
trailing slash, as long as it appears in the URL regex.

Cheers,

Michal

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20160423190320.GC435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Django apparently can't handle that error.

2016-04-23 Thread Neto
Hi, I am trying to delete an Account that delete in cascade others objects, 
but I have a post_delete in Car model that create a Log that have relation 
with this Account.
The django apparently can not handle the error. How to solve this?

Models:

class Account(models.Model):
pass


class Car(models.Model):
account = models.ForeignKey('Account', on_delete=models.CASCADE)


class Log(models.Model):
account = models.ForeignKey('Account', on_delete=models.CASCADE)


class CarLog(Log):
car = models.ForeignKey('Car', null=True, blank=True, 
on_delete=models.SET_NULL)


@receiver(post_delete, sender=Car):
def create_car_log(sender, instance, **kwargs):
try:
CarLog.objects.create(
account=instance.account,
)
except:
pass
 

Shell:


>>> account = Account.objects.create()
>>> car = Car.objects.create(account=account)
>>> CarLog.objects.create(account=account, car=car)
>>> account.delete()  # when delete car will try to create a log related 
with that account, but...

Error:

insert or update on table "myapp_log" violates foreign key constraint 
"myapp_log_account_id_6ea8d7a6_fk_myapp_account_id"
DETAIL:  Key (account_id)=(11) is not present in table "myapp_account".

It's happening this error rather than the exception.





-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/30775c1b-e7e8-439d-9a6e-7cef8667c6ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

2016-04-23 Thread François Schiettecatte
Because the slashes are escaped, this is normal as they are a parameter and not 
part of the path itself.

François

> On Apr 23, 2016, at 2:47 PM, Chris Seberino  wrote:
> 
> Why redirects to foo.com/?next=/some/folder show up as 
> foo.com/?next=%2Fsome%2Ffolder in browser?  (i.e. how remove the %2F's? )
> 
> Is there a function I can call on URLs built in a view to avoid that?
> 
> cs
> 
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/137f689f-306d-4528-82cd-03413b747f2c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: Django apparently can't handle that error.

2016-04-23 Thread Stephen J. Butler
Look a little closer at the error message:

Error:
>
> insert or update on table "myapp_log" violates foreign key constraint 
> "myapp_log_account_id_6ea8d7a6_fk_myapp_account_id"
> DETAIL:  Key (account_id)=(11) is not present in table "myapp_account".
>
> It's happening this error rather than the exception.
>

The table is myapp_log, not myapp_carlog. The error isn't in the
post_delete signal you're showing up. Do you have a post_delete for Account
objects?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxXa4NNr9kX6DDgfhZYBE%3DZxUnwrLKVxpe1_%2B%3DirYGK%3DRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django apparently can't handle that error.

2016-04-23 Thread Neto
Stephen, CarLog is inheriting Log.

Em sábado, 23 de abril de 2016 17:14:57 UTC-3, Stephen Butler escreveu:
>
> Look a little closer at the error message:
>
> Error:
>>
>> insert or update on table "myapp_log" violates foreign key constraint 
>> "myapp_log_account_id_6ea8d7a6_fk_myapp_account_id"
>> DETAIL:  Key (account_id)=(11) is not present in table "myapp_account".
>>
>> It's happening this error rather than the exception.
>>
>
> The table is myapp_log, not myapp_carlog. The error isn't in the 
> post_delete signal you're showing up. Do you have a post_delete for Account 
> objects?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/92e72312-5678-428b-ad7f-360ad911ceaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django apparently can't handle that error.

2016-04-23 Thread Stephen J. Butler
Sorry, I did miss that.

I created a quick test project in 1.9 and ran your sample. It works fine
for me. The delete() returns that it deleted 4 objects: the Account, Car,
Log, and CarLog. There's something else in your project that is causing the
error.

On Sat, Apr 23, 2016 at 3:42 PM, Neto  wrote:

> Stephen, CarLog is inheriting Log.
>
>
> Em sábado, 23 de abril de 2016 17:14:57 UTC-3, Stephen Butler escreveu:
>>
>> Look a little closer at the error message:
>>
>> Error:
>>>
>>> insert or update on table "myapp_log" violates foreign key constraint 
>>> "myapp_log_account_id_6ea8d7a6_fk_myapp_account_id"
>>> DETAIL:  Key (account_id)=(11) is not present in table "myapp_account".
>>>
>>> It's happening this error rather than the exception.
>>>
>>
>> The table is myapp_log, not myapp_carlog. The error isn't in the
>> post_delete signal you're showing up. Do you have a post_delete for Account
>> objects?
>>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/92e72312-5678-428b-ad7f-360ad911ceaa%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

2016-04-23 Thread Chris Seberino


On Saturday, April 23, 2016 at 2:47:58 PM UTC-5, François Schiettecatte 
wrote:
>
> Because the slashes are escaped, this is normal as they are a parameter 
> and not part of the path itself. 
>
> Why URLs created by Django show /'s instead of %2F's?  The Django code 
knows how to
fix the appearance?!

The escaped version only appears on handmade URLs created in a view and used
for a redirect?  Somehow I'm omitting some magic Django code uses. 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1add5bc5-23df-4617-a3ed-f624d93cff4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

2016-04-23 Thread Stephen J. Butler
URLs have different parts or components. The different parts use different
escaping rules.

foo.com/?next=/some/folder

foo.com: uses DNS escaping rules

/: uses path escaping rules, which allows / as a path separator

next=%2Fsome%2Ffolder: uses query parameter escaping rules, which does not
allow "/"

Stuff after a "?" but before a "#" are query parameters, and it follows
different escaping rules than the path part.

On Sat, Apr 23, 2016 at 4:38 PM, Chris Seberino  wrote:

>
>
> On Saturday, April 23, 2016 at 2:47:58 PM UTC-5, François Schiettecatte
> wrote:
>>
>> Because the slashes are escaped, this is normal as they are a parameter
>> and not part of the path itself.
>>
>> Why URLs created by Django show /'s instead of %2F's?  The Django code
> knows how to
> fix the appearance?!
>
> The escaped version only appears on handmade URLs created in a view and
> used
> for a redirect?  Somehow I'm omitting some magic Django code uses.
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1add5bc5-23df-4617-a3ed-f624d93cff4d%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Why / added automatically to all urls but base url?

2016-04-23 Thread Chris Seberino
I have this urlpattern to map base url (easycharting.tk/) to a view called 
home...

urlpatterns = [django.conf.urls.url("^$", mvc.controllers.controllers.home)]

If you visit easycharting.tk/ you'll notice it automatically REMOVES the ending 
/.

Why?

For all other suburls, it ADDS the missing /!?!?

Thanks!

cs

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/90153b14-f741-4f1e-a9cd-d7d280d0f2c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with testing of custom Django admin actions

2016-04-23 Thread Camilo Torres
On Thursday, April 21, 2016 at 9:16:25 AM UTC-4:30, Derek wrote:
>
> Hi
>
> I am looking for help with writing tests for custom Django admin actions; 
> both with and without intermediate pages (ones containing forms).
>
> I confess (hangs head in shame) that I have written lots of actions, but 
> not added any tests for these to my test suite.  It would be great if there 
> were official docs for how to write tests (are there?) but, failing that, a 
> link to some kind of "definitive" tutorial would be great.  Googling seems 
> to produce lots of StackOverflow Q&A or snippets from personal blogs, but 
> no fully worked / comprehensive examples.
>
> Any help or Useful Pointers appreciated.
>
> Thanks
> Derek
>

Hi,
* https://docs.djangoproject.com/en/1.9/intro/tutorial05/
* https://docs.djangoproject.com/en/1.9/topics/testing/ 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/962972c3-61d4-44da-80cc-8825e0834d06%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: remove ./ from commands

2016-04-23 Thread Camilo Torres
On Thursday, April 21, 2016 at 6:55:53 AM UTC-4:30, 
ken@catapultconsulting.net wrote:
>
> I just installed django 1.9.5.  Now I have to type ./manage.py when I used 
> to just type manage.py.  How do I get rid of the need to type ./ 
> osx el capitan
>

Hi,
export PAHT=$PATH:.
then run your command. 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cd5705c4-6121-4479-8d0b-2ce61350c644%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Authentication for mobile apps

2016-04-23 Thread Camilo Torres
On Friday, April 22, 2016 at 8:41:07 AM UTC-4:30, Deep Shah wrote:
>
> I am new to Django. I want to know how does authentication work for mobile 
> apps. How do I keep the user logged in? Is there any in-built way in Django 
> to manage tokens or something similar for mobile apps?
>

Hi,
1. If you are talking about 'native' mobile apps, like Android apps or iOS 
apps, these apps have nothing to do with django. These apps have their own 
authentication systems you should investigate for each platform.
1. If you are talkin about 'mobile web apps', these are apps running in a 
webserver and accessed through a web browser. Being run in a web server 
means you can use django and you can use the same authentication mechanism 
used for desktop web apps. There is no difference.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7f9e1d9-a12f-41ef-a325-97c83ca68eb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

2016-04-23 Thread Chris Seberino
But I still don't see why sometimes the slash is escaped then sometimes it 
isn't. I've seen both ways for query parameters The ugly Escape version 
shows up when I have handmade URLs but not when Django creates the next URL 
itself like for logging in 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4301c013-2b27-427b-8f0e-d7e13bc13112%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question about admin.StackedInline

2016-04-23 Thread Camilo Torres


On Friday, April 22, 2016 at 12:37:40 PM UTC-4:30, Said Akhmedbayev wrote:
>
> Thank you in advance!
>
> I am new to Django, trying to build a small app for my friend. The app 
> mock-up is here  
>
> Basically, the app will include Units/Lessons with Subsection, each 
> Subsection will end with several questions.
>
> Here my models.py
>
> from django.db import models
>
>
> # Create your models here.
> class Unit(models.Model):
> title = models.CharField(max_length=150, blank=True, null=True)
> unit_number = models.PositiveIntegerField(blank=True, null=True, 
> default=1)
>
> def __str__(self):
> return self.title
>
>
>
> class SubSection(models.Model):
> subsection_text = models.TextField(default='SUBSECTION TEXT')
> question = models.ForeignKey(Unit, 
> related_name='subsection_to_question')
>
>
> class Question(models.Model):
> question_text = models.CharField(max_length=2000, default='QUESTION 
> TEXT')
> subsection = models.ForeignKey(SubSection, 
> related_name='question_to_subsection',)
>
> And here is my admin.py
>
> from django.contrib import admin
> from .models import Unit, SubSection
>
>
> # Register your models here.
> class SubSectionInline(admin.StackedInline):
> model = SubSection
>
>
> @admin.register(Unit)
> class UnitAdmin(admin.ModelAdmin):
> inlines = [
> SubSectionInline,
> ]
>
> Here is what I see in the admin 
>
>
> 
> It is all nice, but it is not exactly what I want :-). Here is what I want 
> to see, it is photoshop mock-up
>
>
> 
>
> My questions are:
>
> Is this even possible to do with the approach I took?
>
> If it is possible, can you please help me to figure out how to make it?
>

Hi,
You should take a look at the django-nested-admin project: 
https://pypi.python.org/pypi/django-nested-admin/3.0.0
 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b00157dd-9ade-4f6d-a462-c433ba1f8ad3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

2016-04-23 Thread Stephen J. Butler
You mean on the standard login form? The hidden "next" form value? That
value isn't part of a URL so it isn't URL escaped. It's part of the HTML
attribute value, so it is HTML attribute escaped.

On Sat, Apr 23, 2016 at 6:19 PM, Chris Seberino  wrote:

> But I still don't see why sometimes the slash is escaped then sometimes it
> isn't. I've seen both ways for query parameters The ugly Escape version
> shows up when I have handmade URLs but not when Django creates the next URL
> itself like for logging in
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4301c013-2b27-427b-8f0e-d7e13bc13112%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Help with defining Models for ManyToMany and OneToMany relationships...

2016-04-23 Thread Camilo Torres
On Saturday, April 23, 2016 at 10:00:45 AM UTC-4:30, Bruce Whealton wrote:
>
> Hello all,
>   So, I setup django in a virtualenv on my Ubuntu environment.  I 
> was reading the docs and thought I had things right 
> for creating the 3 models I wanted with this application. I am using 
> Postgresql.  I have the Postgresql driver for Python/Django installed
> in the virtualenv.  It is a "Contacts" app.  
> First question: Do django model fields default to required unless you use 
> blank=True, null=True?
> Many of my fields, I want to have optional.
>
> I have a class called Contact, a class called Organization and a class 
> called Connection.  
> I wanted to use the Organization as a foreign key on the Contact model.  I 
> could have more than one contact from
> an Organization.  The Connection model is inspired by the Google Plus idea 
> of "Circles" - e.g. friends,
> family, following, etc.   So, this would be a many-to-many relationship.  
>
> My problems are (1) I cannot create connections without specifying a 
> contact.  
> (2) If I was adding a contact using the admin interface, how do I allow no 
> value for that foreign field
> or allow for some kind of ajax type of text completion?  If a person is 
> family or friend, I may not need
> to list an Organization for them.
> (3) I would like to support multiple connection types - e.g. following, 
> employer, etc.
>
> So, here is my apps models.py file:
> 
>
> from django.db import models
>
>
> class Contact(models.Model):
> name = models.CharField(max_length=40)
> Organization = models.CharField(max_length=50)
> street_line1 = models.CharField("Street Line 1", max_length=50)
> street_line2 = models.CharField("Street Line 2", max_length=50)
> city = models.CharField(max_length=40)
> state = models.CharField(max_length=40)
> zipcode = models.CharField(max_length=20, blank=True, null=True)
> phone1 = models.CharField(max_length=20)
> phone2 = models.CharField(max_length=20)
> email = models.EmailField(max_length=60)
>
>
> class Organization(models.Model):
> name = models.CharField(max_length=60)
> street_line1 = models.CharField("Street Line 1", max_length=50)
> street_line2 = models.CharField("Street Line 2", max_length=50)
> city = models.CharField(max_length=40)
> state = models.CharField(max_length=40)
> zipcode = models.CharField(max_length=20, blank=True, null=True,)
> phone = models.CharField(max_length=20)
> email = models.EmailField(max_length=60)
> website = models.URLField(max_length=90)
> contact_name = models.ForeignKey(Contact, on_delete=models.CASCADE)
>
>
> class Connection(models.Model):
> type = models.CharField(max_length=60)
> contact_name = models.ManyToManyField(Contact)   
>
> >>>
> Thanks in advance for any suggestions,
> Bruce 
>

Hi,
1.  Do django model fields default to required unless you use blank=True, 
null=True?
This may help you understand 
that: 
http://stackoverflow.com/questions/8609192/differentiate-null-true-blank-true-in-django

2. I think you need a foreign key on Contact to Organization:

class Contact(models.Model):
name = 

organization = models.ForeignKey('Organization', null=True, blank=True)

That way you can have many contacts to a single organization. The 
contact_name in Organizations allows only 1 Contact, but you said you need 
many.

3. I cannot create connections without specifying a contact.
I don't see why not. Do you get any error?

4. If I was adding a contact using the admin interface, how do I allow no 
value for that foreign field
By setting null=True, blank=True for the ForeignKey field. Notice Contact 
do not have any ForeignKey in your example.

5. or allow for some kind of ajax type of text completion?
I have used this in the 
past: https://django-autocomplete-light.readthedocs.org/en/master/

6.  I would like to support multiple connection types - e.g. following, 
employer, etc.
You already have a 'type' field in Connections model. First I suggest to 
use a different name for the field: type is a reserved Python word.
Second, you can add choices to the field.

from django.utils.translation import ugettext as _
...
class Connection(models.Model):
CHOICES = (('follower', _('Follower')),
   ('employer', _('Employer')),
   ('unspecified', _('Unspecified')),
  )
connection_type = models.CharField(max_length=20, choices=CHOICES)
contact_name = models.ManyToManyField(Contact)  



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6918823e-

Re: Why / added automatically to all urls but base url?

2016-04-23 Thread Chris Seberino
Nevermindthis is weird but the / at end was there but Chrome browser 
doesn't display it.
When I pasted the url into a terminal is was there.  Also, using curl I got 
the real info
and it was there. Weird

On Saturday, April 23, 2016 at 5:10:52 PM UTC-5, Chris Seberino wrote:
>
> I have this urlpattern to map base url (easycharting.tk/) to a view 
> called home...
>
> urlpatterns = [django.conf.urls.url("^$", 
> mvc.controllers.controllers.home)]
>
> If you visit easycharting.tk/ you'll notice it automatically REMOVES the 
> ending /.
>
> Why?
>
> For all other suburls, it ADDS the missing /!?!?
>
> Thanks!
>
> cs
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/42829606-a29d-4851-8e3b-65be29b136b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why redirects to foo.com/?next=/some/folder show up as foo.com/?next=%2Fsome%2Ffolder in browser? (i.e. how remove the %2F's? )

2016-04-23 Thread Chris Seberino

Sorry the culprit that is escaping slashes is urlencode not django

if you do urllib.parse.urlencode( {"next" : "/a/b/c"} ) is python3 you'll 
see lots of %2F's in the output..

I want to get rid of those if that's not a problem

On Saturday, April 23, 2016 at 7:50:21 PM UTC-5, Stephen Butler wrote:
>
> You mean on the standard login form? The hidden "next" form value? That 
> value isn't part of a URL so it isn't URL escaped. It's part of the HTML 
> attribute value, so it is HTML attribute escaped.
>
> On Sat, Apr 23, 2016 at 6:19 PM, Chris Seberino  > wrote:
>
>> But I still don't see why sometimes the slash is escaped then sometimes 
>> it isn't. I've seen both ways for query parameters The ugly Escape 
>> version shows up when I have handmade URLs but not when Django creates the 
>> next URL itself like for logging in
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/4301c013-2b27-427b-8f0e-d7e13bc13112%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: [django1.9] Url template tag, dotted path and decorator

2016-04-23 Thread Camilo Torres
On Saturday, April 23, 2016 at 1:17:26 PM UTC-4:30, François Magimel wrote:
>
> Hi! 
>
> I'm facing an issue reversing a dotted path with django 1.9.4. Here are 
> more details. 
>
> I pass a dotted path to the django template tag "url": 
> "{% url 'my.app.view.func' arg %}" 
> And the function "my.app.view.func" has a decorator which is using "arg". 
> My problem is : when displaying my template, I get a NoReverseMatch error. 
> But I don't have any error: 
>   - when I use the name of the url (defined in my urls.py file) or 
>   - when I use the dotted path and remove my (simple) decorator. 
>
> I know that passing a dotted path to url is deprecated since django 1.8 
> [0][1], but not removed yet. So, I think there is something wrong with 
> dotted path and decorators, but I can't find what… 
>
> PS: my decorator only redirects to another view… 
>
> Thanks, 
> François 
>
>
> [0] 
> https://docs.djangoproject.com/en/1.8/releases/1.8/#passing-a-dotted-path-to-reverse-and-url
>  
> [1] https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#url 
>

Hi,
May be you can use functools.wraps from Python standard library.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/31e70c60-a119-4bba-a903-6af4affd5bbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django apparently can't handle that error.

2016-04-23 Thread Neto
Stephen, I am using Django 1.9.5, PostgreSQL 9.3
I do not know, maybe the order of the apps may be interfering in the way 
Django sorts the commands to be sent to the postgresql.

INSTALLED_APPS = [
'core',  # here: Account, Log
'myapp',  # here: Car, CarLog


What is happening is that post_delete is trying to create a log for an 
account that does not exist. The exception doesn't works.
This seems to be a bug.

Em sábado, 23 de abril de 2016 18:28:08 UTC-3, Stephen Butler escreveu:
>
> Sorry, I did miss that.
>
> I created a quick test project in 1.9 and ran your sample. It works fine 
> for me. The delete() returns that it deleted 4 objects: the Account, Car, 
> Log, and CarLog. There's something else in your project that is causing the 
> error.
>
> On Sat, Apr 23, 2016 at 3:42 PM, Neto 
> > wrote:
>
>> Stephen, CarLog is inheriting Log.
>>
>>
>> Em sábado, 23 de abril de 2016 17:14:57 UTC-3, Stephen Butler escreveu:
>>>
>>> Look a little closer at the error message:
>>>
>>> Error:

 insert or update on table "myapp_log" violates foreign key constraint 
 "myapp_log_account_id_6ea8d7a6_fk_myapp_account_id"
 DETAIL:  Key (account_id)=(11) is not present in table "myapp_account".

 It's happening this error rather than the exception.

>>>
>>> The table is myapp_log, not myapp_carlog. The error isn't in the 
>>> post_delete signal you're showing up. Do you have a post_delete for Account 
>>> objects?
>>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/92e72312-5678-428b-ad7f-360ad911ceaa%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: A Problem about UnicodeEncodeError

2016-04-23 Thread nku . mtl
Yeah,this problem is same as what I met.
However the solution the author provided didn't work on my machine.
My friend started the project successfully with python2.x,so I decided to 
change the version of python.
Thank you very much for your help!

在 2016年4月22日星期五 UTC+8下午10:41:29,Steven Crockett写道:
>
> Hi. Could you post more of the exception traceback?
>
> Here is a workaround others have found for a problem similar to yours:
> https://code.djangoproject.com/ticket/23704
>
> It seems to be something to do with your PATH setting within Windows 
> possibly containing some non-standard character.
>
>
> On Friday, April 22, 2016 at 9:09:23 AM UTC-4, nku...@gmail.com wrote:
>>
>> Hello,
>> I'm a beginner of Python.
>> Recently,I want to learn something about django.But I meet a problem:
>> I created a django project following the tutorial successfully , but 
>> when I ran the command "python manage.py runserver",
>>
>> the cmd show the error information:
>> UnicodeEncodeError: 'mbcs' codec can't encode characters in 
>> position 0--1: invalid character
>>
>> I have search for a long time but didn't get the solution.
>> Could anyone please tell me how to fix it?
>> Thanks.
>>
>> P.S.The veision of my python is 3.5.1,and the version of django is 
>> 1.9.5.My OS is windows8.1
>>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8555253a-973a-40af-9ea3-5ecd2c62d4ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django apparently can't handle that error.

2016-04-23 Thread Stephen J. Butler
Ahh, Postgres is the problem. When your exception is thrown then Postgres
aborts the rest of the transaction. That's how its transaction handling
works. Even though you ignore the exception in the myapp code, it will
still cause the transaction to abort when Django tries to call commit().
When I was testing I was using sqlite, which behaves differently.

See the note here:
https://docs.djangoproject.com/en/1.9/topics/db/transactions/#handling-exceptions-within-postgresql-transactions

This works for me:

@receiver(post_delete, sender=Car)
def create_car_log(sender, instance, **kwargs):
sid = transaction.savepoint()
try:
CarLog.objects.create(
account=instance.account,
)
transaction.savepoint_commit(sid)
except:
transaction.savepoint_rollback(sid)

What I don't get is that using a "with transaction.atomic()" inside the try
block should do the same thing. But it's not. Maybe someone else knows?

On Sat, Apr 23, 2016 at 10:19 PM, Neto  wrote:

> Stephen, I am using Django 1.9.5, PostgreSQL 9.3
> I do not know, maybe the order of the apps may be interfering in the way
> Django sorts the commands to be sent to the postgresql.
>
> INSTALLED_APPS = [
> 'core',  # here: Account, Log
> 'myapp',  # here: Car, CarLog
>
>
> What is happening is that post_delete is trying to create a log for an
> account that does not exist. The exception doesn't works.
> This seems to be a bug.
>
> Em sábado, 23 de abril de 2016 18:28:08 UTC-3, Stephen Butler escreveu:
>>
>> Sorry, I did miss that.
>>
>> I created a quick test project in 1.9 and ran your sample. It works fine
>> for me. The delete() returns that it deleted 4 objects: the Account, Car,
>> Log, and CarLog. There's something else in your project that is causing the
>> error.
>>
>> On Sat, Apr 23, 2016 at 3:42 PM, Neto  wrote:
>>
>>> Stephen, CarLog is inheriting Log.
>>>
>>>
>>> Em sábado, 23 de abril de 2016 17:14:57 UTC-3, Stephen Butler escreveu:

 Look a little closer at the error message:

 Error:
>
> insert or update on table "myapp_log" violates foreign key constraint 
> "myapp_log_account_id_6ea8d7a6_fk_myapp_account_id"
> DETAIL:  Key (account_id)=(11) is not present in table "myapp_account".
>
> It's happening this error rather than the exception.
>

 The table is myapp_log, not myapp_carlog. The error isn't in the
 post_delete signal you're showing up. Do you have a post_delete for Account
 objects?

>>> --
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/92e72312-5678-428b-ad7f-360ad911ceaa%40googlegroups.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/02b1ab5b-d7e3-4df2-9738-9c1636e931c5%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: A Problem about UnicodeEncodeError

2016-04-23 Thread Mike Dewhirst

On 24/04/2016 1:48 PM, nku@gmail.com wrote:

Yeah,this problem is same as what I met.
However the solution the author provided didn't work on my machine.
My friend started the project successfully with python2.x,so I decided
to change the version of python.
Thank you very much for your help!

在 2016å¹´4月22日星期五 UTC+8ä¸‹å ˆ10:41:29,Steven Crockettå†™é “ï¼š

Hi. Could you post more of the exception traceback?

Here is a workaround others have found for a problem similar to yours:
https://code.djangoproject.com/ticket/23704



If you look at the path displayed in that ticket and pointed to by the 
little blue arrow, you can see the Django project ("myfirstapp") is 
created in the desktop folder.


I believe that is the problem. The desktop is a magic place in Windows 
and I have no doubt that Microsoft uses "special" characters in the path 
so it recognises the desktop to perform its magic.


It is probably mis-recognised by Python as a 'mbcs' encoding and causes 
the error.


I have been using Python 2 and 3 on Windows for years without problems - 
which knowing Microsoft I consider to be something of a miracle!


Move your project off the desktop and you won't need any workarounds.

Mike






It seems to be something to do with your PATH setting within Windows
possibly containing some non-standard character.


On Friday, April 22, 2016 at 9:09:23 AM UTC-4, nku...@gmail.com wrote:

Hello,
I'm a beginner of Python.
Recently,I want to learn something about django.But I meet a
problem:
    I created a django project following the tutorial
successfully , but when I ran the command "python manage.py
runserver",

    the cmd show the error information:
        UnicodeEncodeError: 'mbcs' codec can't encode
characters in position 0--1: invalid character

I have search for a long time but didn't get the solution.
Could anyone please tell me how to fix it?
Thanks.

P.S.The veision of my python is 3.5.1,and the version of django
is 1.9.5.My  OS is windows8.1

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/8555253a-973a-40af-9ea3-5ecd2c62d4ed%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


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


Re: Help with defining Models for ManyToMany and OneToMany relationships...

2016-04-23 Thread Mike Dewhirst

On 23/04/2016 11:22 PM, Bruce Whealton wrote:

Hello all,
          So, I setup django in a virtualenv on my Ubuntu
environment. Â I was reading the docs and thought I had things rightÂ
for creating the 3 models I wanted with this application. I am using
Postgresql. Â I have the Postgresql driver for Python/Django installed
in the virtualenv. Â It is a "Contacts" app. Â
First question: Do django model fields default to required unless you
use blank=True, null=True?
Many of my fields, I want to have optional.

I have a class called Contact, a class called Organization and a class
called Connection. Â


I think you should rethink your Contact and Organization classes and see 
if you can eliminate one or the other. A single table for both would 
simplify the problem because the Connection class can implement as many 
connections as you like.


For example ...

class ContactOrOrganization(etc):
various detail fields ...

class Connection(etc):
organization = ForeignKey("ContactOrOrganization",
related_name="organization")
contact = ForeignKey("ContactOrOrganization",
related_name="contact")

Just because I used related_name that way means nothing. You can connect 
contacts together or organizations together. Also, you can add other 
fields to Connection with which to describe the relationship.


Mike


I wanted to use the Organization as a foreign key on the Contact model.
 I could have more than one contact from
an Organization. Â The Connection model is inspired by the Google Plus
idea of "Circles" - e.g. friends,
family, following, etc. Â  So, this would be a many-to-many relationship. Â

My problems are (1) I cannot create connections without specifying a
contact. Â
(2) If I was adding a contact using the admin interface, how do I allow
no value for that foreign field
or allow for some kind of ajax type of text completion? Â If a person is
family or friend, I may not need
to list an Organization for them.
(3) I would like to support multiple connection types - e.g. following,
employer, etc.

So, here is my apps models.py file:
 

from django.db import models


class Contact(models.Model):
    name = models.CharField(max_length=40)
    Organization = models.CharField(max_length=50)
    street_line1 = models.CharField("Street Line 1", max_length=50)
    street_line2 = models.CharField("Street Line 2", max_length=50)
    city = models.CharField(max_length=40)
    state = models.CharField(max_length=40)
    zipcode = models.CharField(max_length=20, blank=True, null=True)
    phone1 = models.CharField(max_length=20)
    phone2 = models.CharField(max_length=20)
    email = models.EmailField(max_length=60)


class Organization(models.Model):
    name = models.CharField(max_length=60)
    street_line1 = models.CharField("Street Line 1", max_length=50)
    street_line2 = models.CharField("Street Line 2", max_length=50)
    city = models.CharField(max_length=40)
    state = models.CharField(max_length=40)
    zipcode = models.CharField(max_length=20, blank=True, null=True,)
    phone = models.CharField(max_length=20)
    email = models.EmailField(max_length=60)
    website = models.URLField(max_length=90)
    contact_name = models.ForeignKey(Contact, on_delete=models.CASCADE)


class Connection(models.Model):
    type = models.CharField(max_length=60)
    contact_name = models.ManyToManyField(Contact)  Â

 >>>
Thanks in advance for any suggestions,
BruceÂ

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/caede40b-640c-4e8d-997d-b76c62922c19%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


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