Re: turn on "string_if_invalid" as a ‘development default’

2016-01-19 Thread guettli


Am Montag, 18. Januar 2016 12:02:15 UTC+1 schrieb James Schneider:
>
> A second batch of tests?
>>
>> I am unsure if I understood you: Do you mean new tests, or running the 
>> same
>> tests again, with a different settings file?
>>
>
> I meant the latter. Sorry for not being clear.
>  
>
>>
>> If the first: write new tests: How should these tests be different from 
>> the existing tests?
>>
>> If the second: Why not run the test with the settings which have 
>> string_if_invalid enabled in the first run?
>> What do you gain by running the tests twice?
>>
>
> The two sets of tests could potentially provide two sets of differing 
> results. The development setting you want to change is known to negatively 
> interact with templates used by the Django admin and probably third-party 
> applications that provide templates, per the link that you provided. With 
> that setting changed, you are testing an application that intentionally 
> behaves differently than what will be seen in production. That makes me 
> uncomfortable.
>
>
Yes, I understand "...behaves differently than what will be seen in 
production. That makes me uncomfortable." I see it the same.

I would like  string_if_invalid to raise an exception immediately. Maybe 
even in prod, since: "...behaves differently than what will be seen in 
production. That makes me uncomfortable." 

Zen of Python:

> Errors should never pass silently. 
 

For me, that means running two sets of tests. One of them will closely 
> match the production settings (probably the settings file you're using 
> now), and the other can be tweaked to potentially catch edge-cases or other 
> uncommon bugs that you can/have run in to, or other failure points that may 
> not be easily exposed by the standard settings file. Perhaps the second 
> customized set of tests may not be something that you build into your CI, 
> but may be part of a manual examination performed at various milestones. It 
> would depend on your workflow and CI process, and how often you think these 
> particular bugs may present themselves. Maybe only as a pre-release final 
> check?
>
>
We have no "pre-release final check/test". We run the whole test-suite 
twice daily. This is done automatically be jenkins.
We try to automate as much as possible. Manual examination is possible, but 
who wants to do this? I would like to have it automated.
All tests run in around 10 minutes. 

I guess we will see bugs like  four times per year. 
With "like this" I mean:

 * bugs caused by the template engine returning the empy string instead of 
an exception 
 * bugs which are not detected by CI and get into production

 

> Or, if you don't use the admin or any 3rd party applications, you may be 
> safe in enabling it. I personally wouldn't unless I was also doing so in 
> production.
>
>

Yes, dev and prod should not be much different

 Thank you for your input.

Regards,
  Thomas

-- 
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/892db691-3437-461e-80bc-1396ef854834%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: turn on "string_if_invalid" as a ‘development default’

2016-01-19 Thread James Schneider
>
> We have no "pre-release final check/test". We run the whole test-suite
> twice daily. This is done automatically be jenkins.
> We try to automate as much as possible. Manual examination is possible,
> but who wants to do this? I would like to have it automated.
> All tests run in around 10 minutes.
>

Hence the reason I mentioned that it will be dependent on your workflow. If
this is something you want to automate, obviously you'll need to figure out
how to get it to work with your CI implementation.


>
> I guess we will see bugs like  four times per year.
>
With "like this" I mean:
>
>  * bugs caused by the template engine returning the empy string instead of
> an exception
>  * bugs which are not detected by CI and get into production
>

I did a bit of poking around and I found this:

https://docs.djangoproject.com/en/dev/topics/testing/tools/#overriding-settings


It actually looks like it wouldn't be too difficult to take specific
existing tests and re-run them in the same test run with
the string_if_invalid tweaked. That would save you from having to modify
your CI, and would provide coverage in both a 'production mirror' state and
the alternative 'template bug catcher' state. You can probably subclass
your existing test classes and just decorate them appropriately, although
you might have other things you're looking for in those cases.

Never tried it myself, but looks to be worth a shot in your case.

-James

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


regular expression confusion

2016-01-19 Thread Xristos Xristoou
hello,

i have a regular expression confusion error i cant work my app with 
together 2 and 3 line from *my blog/**urls *if i work regardless that lines 
work fine
but i need together for my project.

*my mysite/urls*

url(r'^admin/', include(admin.site.urls)),
url(r'', include('blog.urls')),


*my blog/urls*


1  url(r'^$', views.index, name='index'),
2  url(r'^(?P[^\.]+)/$', views.view_post, name='view_post'),
3  url(r'^(?P[\w-]+)/$', views.view_category, name='view_category')




-- 
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/11ac4eac-af33-4d5b-96e5-6b57826a06b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regular expression confusion

2016-01-19 Thread James Schneider
On Tue, Jan 19, 2016 at 2:30 AM, Xristos Xristoou  wrote:

> hello,
>
> i have a regular expression confusion error i cant work my app with
> together 2 and 3 line from *my blog/**urls *if i work regardless that
> lines work fine
> but i need together for my project.
>
> *my mysite/urls*
>
> url(r'^admin/', include(admin.site.urls)),
> url(r'', include('blog.urls')),
>
>
> The second line should probably be a r'^', rather than just an empty
string.


> *my blog/urls*
>
>
> 1  url(r'^$', views.index, name='index'),
> 2  url(r'^(?P[^\.]+)/$', views.view_post, name='view_post'),
> 3  url(r'^(?P[\w-]+)/$', views.view_category, name='view_category')
>
>
> This is probably not a good URL strategy. Your view_category URL's overlap
with your view_post URL's, which means that your view_category URL's will
never work because [\w-]+ is contained within [^\.]+, which matches any
character except for a \ and period, neither of which will ever be
contained in a common slug format (used by view_category).

Wouldn't it be better and more obvious to namespace the URL's so that what
you are matching is much more clear? Otherwise you'll have no way of
telling a post apart from a category.


2  url(r'^post/(?P[^\.]+)/$', views.view_post, name='view_post'),
3  url(r'^category/(?P[\w-]+)/$', views.view_category,
name='view_category')


-James

-- 
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/CA%2Be%2BciXf%2BVWCDa%2BCER3ZrNRK%2Bwe60Cs34%3DdyLD8MSRXRd9r2hg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: regular expression confusion

2016-01-19 Thread Xristos Xristoou

>
> yeah but now must to change my template tags ? for exable 
>
>
 my first template tags

 {{*posts*.Title}}
>
>

-- 
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/d4f6aa5d-c1e9-4633-b6aa-b2de16ac4e82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regular expression confusion

2016-01-19 Thread Xristos Xristoou

>
> yeah but now must be change mt template tags ?
>
>  

> *for example*
>
>
my first template tags from the main page to the view page

 {{movies.Title}} 

-- 
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/7f8dbf1b-ce7a-4b38-a128-1859683d5b74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regular expression confusion

2016-01-19 Thread Xristos Xristoou
i find it thnx for the help

-- 
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/415764cb-467f-4207-bb85-40887d1d3858%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django admin objectaction confirmation

2016-01-19 Thread 张超
Thank you very much!

在 2016年1月19日星期二 UTC+8下午3:14:49,Andréas Kühne写道:
>
> Hi,
>
> Check how actions work in the admin interface. You should be able to 
> create something that works the same by clicking on a button. See here: 
> https://docs.djangoproject.com/en/1.9/ref/contrib/admin/actions/
>
> The main point is that if you do a http get, you should show the 
> confirmation page, and if you do a post, the action should happen.
>
> Regards,
>
> Andréas
>
> 2016-01-19 6:53 GMT+01:00 张超 >:
>
>> I want to make a confirmation before executing the objectaction when 
>> click the objectaction button ...I have tried to write a js to do that ,but 
>> it doesn't work..how could I make it?
>>
>> -- 
>> 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/a718b7d5-813c-4706-8bee-1941c078fba9%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/f2ea1013-a9aa-473e-8359-b338a0cd6f30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


like query django

2016-01-19 Thread Xristos Xristoou
hello,


i want to create a query for likes in my post details

my html tags

{{movies.likes}} peaple liked this article
Like


my urls


url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'),

url(r'^(?P[0−9]+)/$', views.like_post, name='like_post'),


my view


def like_post(request,pk=1):
 a=Movies.objects.get(pk=pk)
 count=a.likes
 count+=1
 a.likes=count
 a.save()
 return HttpResponseRedirect ( '/posts/view/%s' % pk)


but i have error not work


Page not found (404)Request Method:GETRequest URL:http://127.0.0.1:8000/like/1/

Using the URLconf defined in categories1.urls,  Django tried these URL 
patterns, in this order:   

   1. ^admin/   
   2. ^$ [name='index']   
   3. ^view/(?P[^\.]+)/$[name='view_post']   
   4. ^category/(?P[\w-]+)/$[name='view_category']   
   5. ^(?P[0−9]+)/$ [name='like_post']   
   6.  ^media\/(?P.*)$   

The current URL, like/1/, didn't match any of these.



any idea ?

-- 
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/bd58b974-1c93-498b-a9b3-30503e209e51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: like query django

2016-01-19 Thread Florian Schweikert
On 19/01/16 16:35, Xristos Xristoou wrote:
> url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'),
> url(r'^(?P[0−9]+)/$', views.like_post, name='like_post'),

this defines urls like /1/

> The current URL, |like/1/|, didn't match any of these.

of course it doesn't, you didn't define a like/... url pattern

--
Florian

-- 
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/569E5F25.50500%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.


Re: like query django

2016-01-19 Thread Xristos Xristoou
not work again florian same error again

Τη Τρίτη, 19 Ιανουαρίου 2016 - 5:35:09 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> hello,
>
>
> i want to create a query for likes in my post details
>
> my html tags
>
> {{movies.likes}} peaple liked this article
> Like
>
>
> my urls
>
>
> url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'),
>
> url(r'^(?P[0−9]+)/$', views.like_post, name='like_post'),
>
>
> my view
>
>
> def like_post(request,pk=1):
>  a=Movies.objects.get(pk=pk)
>  count=a.likes
>  count+=1
>  a.likes=count
>  a.save()
>  return HttpResponseRedirect ( '/posts/view/%s' % pk)
>
>
> but i have error not work
>
>
> Page not found (404)Request Method:GETRequest 
> URL:http://127.0.0.1:8000/like/1/
>
> Using the URLconf defined in categories1.urls,  Django tried these URL 
> patterns, in this order:   
>
>1. ^admin/   
>2. ^$ [name='index']   
>3. ^view/(?P[^\.]+)/$[name='view_post']   
>4. ^category/(?P[\w-]+)/$[name='view_category']  
>  
>5. ^(?P[0−9]+)/$ [name='like_post']   
>6.  ^media\/(?P.*)$   
>
> The current URL, like/1/, didn't match any of these.
>
>
>
> any idea ?
>
>

-- 
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/d649cb3c-63cc-4793-ac08-5ac8af7951ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: like query django

2016-01-19 Thread James Schneider
>
> {{movies.likes}} peaple liked this article
> Like
>
>
> This is not how you should generate URL's within your templates. You
should be using the {% url %} tag to automatically generate them:

Like

If using the slug in your urls.conf, your {% url %} tag would look
something like this:

Like


See
https://docs.djangoproject.com/en/dev/intro/tutorial03/#removing-hardcoded-urls-in-templates

my urls
>
>
> url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'),
>
> url(r'^(?P[0−9]+)/$', views.like_post, name='like_post'),
>
>
Your urls.conf should also be modified to avoid clashes down the road. I
would recommend changing this line to imply that you are viewing the post,
rather than prefixing the verb 'view' on the URL with no reference as to
what type of object you are viewing:

url(r'^post/(?P[^\.]+)/$', views.view_post, name='view_post'),


As of now, you are using mysite.com/5 to indicate that you want to like a
post, which makes it difficult to discern that is what you are doing.

Something like this would work.

url(r'^post/(?P[0−9]+)/like/$', views.like_post, name='like_post'),

You can also do this using the slug if you want to keep your URL's looking
the same:

url(r'^post/(?P[^\.]+)/like/$', views.like_post, name='like_post'),

I would recommend always using the slug, or always using the PK, but
not intermixing the two if you can avoid it (keeps things easier to
remember when doing more advanced operations). If you care about SEO,
you'll probably want to use the slug.


See
https://docs.djangoproject.com/en/dev/intro/tutorial03/#writing-more-views

You'll notice they have the verb (action word) after the identifier for the
item that is being acted upon. In psuedo-code English, this translates to
 'here is the post that I want to like' rather than 'I am liking something,
here is a post'. Not sure if that translates well to other languages if
English isn't your first language.

You'll want to set things up this way because it will help keep your URL's
together in one configuration file, and will make your URL scheme much
simpler. Much easier to keep track of all the actions that you can perform
for a particular post (create, update, delete, comment, like, etc.) rather
than having an extensively long list of actions that have actionable
objects. If you add more content types, like a 'news article', then you'll
have to modify two sets of urls.py files or stanzas, one for viewing the
article, and another for the extra actions that can be taken on that
article, which gets cumbersome and difficult to manage.

>
> my view
>
>
> def like_post(request,pk=1):
>  a=Movies.objects.get(pk=pk)
>  count=a.likes
>  count+=1
>  a.likes=count
>  a.save()
>  return HttpResponseRedirect ( '/posts/view/%s' % pk)
>
>
>
You should be using reverse() here rather than the actual URL. There are
examples of this in the tutorial for Django:

https://docs.djangoproject.com/en/1.9/intro/tutorial01/



> but i have error not work
>
>
> Page not found (404)
> Request Method: GET
> Request URL: http://127.0.0.1:8000/like/1/
>
> Using the URLconf defined in categories1.urls,  Django tried these URL 
> patterns, in this order:
>
>1. ^admin/
>2. ^$ [name='index']
>3. ^view/(?P[^\.]+)/$[name='view_post']
>4. ^category/(?P[\w-]+)/$[name='view_category']
>5. ^(?P[0−9]+)/$ [name='like_post']
>6.  ^media\/(?P.*)$
>
> The current URL, like/1/, didn't match any of these.
>
>
>
> any idea ?
>
> You are trying to reach /like/1/, but your urls.py file is configured only
to look for /1/ (line 5).

Please run through the tutorial, which will show you step by step how these
processes work together, and should give you a good basis for URL design.

https://docs.djangoproject.com/en/1.9/intro/tutorial01/

-James

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


Re: Access denied for MySQL user in Django

2016-01-19 Thread Fred Stluka

Galil,

Try this also:

mysql> use mysql;
mysql> delete from user where host='%' and 'user='';
mysql> flush privileges;

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 1/18/16 2:38 AM, Sergiy Khohlov wrote:


Using password no. Have you set notempty password with creating table 
permission?


15 січ. 2016 18:20 "Galil" > пише:


Hi Fred,

The user cdraccess is not the root user and it does not have the
rights to access table 'user'. I deleted the guest user as root
but nothing changes. The problem was not fixed.

On Thursday, 14 January 2016 17:50:21 UTC, Fred Stluka wrote:

Galil,

I had a problem like this a couple years ago, and the solution
was to delete the anonymous MySQL guest user as:

mysql> use mysql;
mysql> delete from user where host='localhost' and 'user='';
mysql> flush privileges;

I'm not sure why Django 1.4 was trying to connect as the guest
user when it had a username and password that it was
supposed to be using, but for some reason it was. Deleting
the guest user from MySQL fixed it for me, and is a good idea
for security reasons anyhow.

--Fred

Fred Stluka -- mailt...@bristle.com --
http://bristle.com/~fred/ 
Bristle Software, Inc -- http://bristle.com -- Glad to be of
service!
Open Source: Without walls and fences, we need no Windows or
Gates.

On 1/14/16 7:11 AM, Galil wrote:


I have created a Django app and which uses MySQL. The
settings.py file in the database sections is:

|DATABASES

={'cdraccess':{'ENGINE':'django.db.backends.mysql','NAME':os.environ.get('CDR_DB_NAME','portal2'),'USER':os.environ.get('CDR_DB_USER','cdraccess'),'HOST':os.environ.get('CDR_DB_HOST','127.0.0.1'),'CONN_MAX_AGE':0,'PASSWORD':os.environ.get('CDR_DB_PASSWORD',''),},'default':{'ENGINE':'django.db.backends.sqlite3','NAME':'db.sqlite3',}}|

I run the app like:

|CDR_DB_PASSWORD='password'CDR_DB_HOST='host_name'./manage.py
runserver|

but I get the following error:

Access denied for user 'cdraccess'@'host_ip_here' (using
password: NO)")

I tried to access the database from terminal, like:

|$ mysql --host=[host_name]--user=cdraccess -p portal2|

and worked fine.

What is going wrong in here? And what does this "(using
password: NO)" mean?


-- 
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/e1c26a0d-a509-46eb-b496-f7f09161e606%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/fa3b7acf-e015-4e0c-abbe-49da80b752a9%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 
http

Filter object by calculating duration from start and end time

2016-01-19 Thread Steven Nash
Hi,

Given an object such as:

class Entry(models.Model):
  start = models.TimeField()
  end = models.TimeField()

I'd like to be able to say something like:

Entry.objects.filter(F('end')-F('start')__gt=time_in_minutes)

Is there a way of doing this without implementing a separate duration field 
and having a setter for start and end update it?

Cheers,
Steve

-- 
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/1e6462bf-fb70-4fb8-8642-492c546fd1b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filter object by calculating duration from start and end time

2016-01-19 Thread Simon Charette
Hi Steve,

You can use annotate for this 

.

from datetime import timedelta

from django.db.models import DurationField, ExpressionWrapper, F

Entry.objects.annotate(
duration=ExpressionWrapper(
F('end') - F('start'), output_field=DurationField()
)
).filter(duration__gte=timedelta(minutes=time_in_minutes)


Cheers,
Simon

Le mardi 19 janvier 2016 13:01:36 UTC-5, Steven Nash a écrit :
>
> Hi,
>
> Given an object such as:
>
> class Entry(models.Model):
>   start = models.TimeField()
>   end = models.TimeField()
>
> I'd like to be able to say something like:
>
> Entry.objects.filter(F('end')-F('start')__gt=time_in_minutes)
>
> Is there a way of doing this without implementing a separate duration 
> field and having a setter for start and end update it?
>
> Cheers,
> Steve
>

-- 
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/52638b82-dbcf-49a4-ad87-afdc81cfd5dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: like query django

2016-01-19 Thread Xristos Xristoou
i follow you not work again first i cant use {% url %} show me template 
error,i thing so i am is very noob
must necesery tu urls for that ?
Τη Τρίτη, 19 Ιανουαρίου 2016 - 5:35:09 μ.μ. UTC+2, ο χρήστης Xristos 
Xristoou έγραψε:
>
> hello,
>
>
> i want to create a query for likes in my post details
>
> my html tags
>
> {{movies.likes}} peaple liked this article
> Like
>
>
> my urls
>
>
> url(r'^view/(?P[^\.]+)/$', views.view_post, name='view_post'),
>
> url(r'^(?P[0−9]+)/$', views.like_post, name='like_post'),
>
>
> my view
>
>
> def like_post(request,pk=1):
>  a=Movies.objects.get(pk=pk)
>  count=a.likes
>  count+=1
>  a.likes=count
>  a.save()
>  return HttpResponseRedirect ( '/posts/view/%s' % pk)
>
>
> but i have error not work
>
>
> Page not found (404)Request Method:GETRequest 
> URL:http://127.0.0.1:8000/like/1/
>
> Using the URLconf defined in categories1.urls,  Django tried these URL 
> patterns, in this order:   
>
>1. ^admin/   
>2. ^$ [name='index']   
>3. ^view/(?P[^\.]+)/$[name='view_post']   
>4. ^category/(?P[\w-]+)/$[name='view_category']  
>  
>5. ^(?P[0−9]+)/$ [name='like_post']   
>6.  ^media\/(?P.*)$   
>
> The current URL, like/1/, didn't match any of these.
>
>
>
> any idea ?
>
>

-- 
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/24bb10c8-98a2-445d-8de2-5abf0f5a618e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filter object by calculating duration from start and end time

2016-01-19 Thread Xristos Xristoou
can used this and for the dates fields ?

Τη Τρίτη, 19 Ιανουαρίου 2016 - 8:01:36 μ.μ. UTC+2, ο χρήστης Steven Nash 
έγραψε:
>
> Hi,
>
> Given an object such as:
>
> class Entry(models.Model):
>   start = models.TimeField()
>   end = models.TimeField()
>
> I'd like to be able to say something like:
>
> Entry.objects.filter(F('end')-F('start')__gt=time_in_minutes)
>
> Is there a way of doing this without implementing a separate duration 
> field and having a setter for start and end update it?
>
> Cheers,
> Steve
>

-- 
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/9c7f2727-e501-4e40-9686-1bc125aa8559%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filter object by calculating duration from start and end time

2016-01-19 Thread Steven Nash
Hi Simon,

Thanks, I'll give that ago.

Cheers,

Steve

On Tuesday, 19 January 2016 18:52:06 UTC, Simon Charette wrote:
>
> Hi Steve,
>
> You can use annotate for this 
> 
> .
>
> from datetime import timedelta
>
> from django.db.models import DurationField, ExpressionWrapper, F
>
> Entry.objects.annotate(
> duration=ExpressionWrapper(
> F('end') - F('start'), output_field=DurationField()
> )
> ).filter(duration__gte=timedelta(minutes=time_in_minutes)
>
>
> Cheers,
> Simon
>
> Le mardi 19 janvier 2016 13:01:36 UTC-5, Steven Nash a écrit :
>>
>> Hi,
>>
>> Given an object such as:
>>
>> class Entry(models.Model):
>>   start = models.TimeField()
>>   end = models.TimeField()
>>
>> I'd like to be able to say something like:
>>
>> Entry.objects.filter(F('end')-F('start')__gt=time_in_minutes)
>>
>> Is there a way of doing this without implementing a separate duration 
>> field and having a setter for start and end update it?
>>
>> Cheers,
>> Steve
>>
>

-- 
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/6cb56c2b-8a18-4e92-9092-5980b8b7a6b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filter object by calculating duration from start and end time

2016-01-19 Thread Simon Charette
Hi Steve,

It looks like it might only work on PostgreSQL unti this bug 
 is fixed.

Simon

Le mardi 19 janvier 2016 14:59:57 UTC-5, Steven Nash a écrit :
>
> Hi Simon,
>
> Thanks, I'll give that ago.
>
> Cheers,
>
> Steve
>
> On Tuesday, 19 January 2016 18:52:06 UTC, Simon Charette wrote:
>>
>> Hi Steve,
>>
>> You can use annotate for this 
>> 
>> .
>>
>> from datetime import timedelta
>>
>> from django.db.models import DurationField, ExpressionWrapper, F
>>
>> Entry.objects.annotate(
>> duration=ExpressionWrapper(
>> F('end') - F('start'), output_field=DurationField()
>> )
>> ).filter(duration__gte=timedelta(minutes=time_in_minutes)
>>
>>
>> Cheers,
>> Simon
>>
>> Le mardi 19 janvier 2016 13:01:36 UTC-5, Steven Nash a écrit :
>>>
>>> Hi,
>>>
>>> Given an object such as:
>>>
>>> class Entry(models.Model):
>>>   start = models.TimeField()
>>>   end = models.TimeField()
>>>
>>> I'd like to be able to say something like:
>>>
>>> Entry.objects.filter(F('end')-F('start')__gt=time_in_minutes)
>>>
>>> Is there a way of doing this without implementing a separate duration 
>>> field and having a setter for start and end update it?
>>>
>>> Cheers,
>>> Steve
>>>
>>

-- 
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/3bd1db8e-0b53-4b3b-b781-51e4cc8a687c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filter object by calculating duration from start and end time

2016-01-19 Thread Steven Nash
That's fine as am using Postgres on centos 7

Cheers
Steve 

Sent from my iPhone

> On 19 Jan 2016, at 21:19, Simon Charette  wrote:
> 
> Hi Steve,
> 
> It looks like it might only work on PostgreSQL unti this bug is fixed.
> 
> Simon
> 
> Le mardi 19 janvier 2016 14:59:57 UTC-5, Steven Nash a écrit :
>> 
>> Hi Simon,
>> 
>> Thanks, I'll give that ago.
>> 
>> Cheers,
>> 
>> Steve
>> 
>>> On Tuesday, 19 January 2016 18:52:06 UTC, Simon Charette wrote:
>>> Hi Steve,
>>> 
>>> You can use annotate for this.
>>> 
>>> from datetime import timedelta
>>> 
>>> from django.db.models import DurationField, ExpressionWrapper, F
>>> 
>>> Entry.objects.annotate(
>>> duration=ExpressionWrapper(
>>> F('end') - F('start'), output_field=DurationField()
>>> )
>>> ).filter(duration__gte=timedelta(minutes=time_in_minutes)
>>> 
>>> 
>>> Cheers,
>>> Simon
>>> 
>>> Le mardi 19 janvier 2016 13:01:36 UTC-5, Steven Nash a écrit :
 
 Hi,
 
 Given an object such as:
 
 class Entry(models.Model):
   start = models.TimeField()
   end = models.TimeField()
 
 I'd like to be able to say something like:
 
 Entry.objects.filter(F('end')-F('start')__gt=time_in_minutes)
 
 Is there a way of doing this without implementing a separate duration 
 field and having a setter for start and end update it?
 
 Cheers,
 Steve
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Django users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/django-users/xIP7hhp0WqQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/3bd1db8e-0b53-4b3b-b781-51e4cc8a687c%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/1E3B4129-5341-4968-990C-3C2E8E8225A6%40bitsolver.co.uk.
For more options, visit https://groups.google.com/d/optout.


Nullable ChoiceField on ModelForm - has_changed always True

2016-01-19 Thread steve byerly
I have a model with a nullable field (PositiveSmallIntegerField) with 
defined choices. When I make a ModelForm for the model and do not select a 
value for this field, the field always comes back in the changed data. The 
reason is that the empty choice value, the data_value, is an empty string, 
while the initial_value is None.

I can override the base field and make a TypedChoiceField, and provide a 
function to coerce which returns None if the value is an empty string.

Is this the only route, or is there a better way to accomplish this?

-- 
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/1e11369b-7bcb-432f-acb6-c3785328b642%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Nullable ChoiceField on ModelForm - has_changed always True

2016-01-19 Thread steve byerly
Also of note, I recently upgraded to Django 1.9 from Django 1.7 where this 
was working fine. It looks like this commit is the cause of my problem:
https://github.com/django/django/commit/ff077cd6496b6f82195e2dc040f70e19e7c206c9

On Tuesday, January 19, 2016 at 4:23:00 PM UTC-8, steve byerly wrote:
>
> I have a model with a nullable field (PositiveSmallIntegerField) with 
> defined choices. When I make a ModelForm for the model and do not select a 
> value for this field, the field always comes back in the changed data. The 
> reason is that the empty choice value, the data_value, is an empty string, 
> while the initial_value is None.
>
> I can override the base field and make a TypedChoiceField, and provide a 
> function to coerce which returns None if the value is an empty string.
>
> Is this the only route, or is there a better way to accomplish this?
>

-- 
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/6c38874b-b876-43a5-827b-fcf8d48365cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


override django object action change_form.html

2016-01-19 Thread 张超
I want to override the change_from.html included in the directory 
django_object_actions/templates/django_object_actions/  ...I copy the  
change_from.html and put it in my app directory- 
myapp/templates/admin/django_object_actions/ ,but it can't work! 

-- 
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/2b9d5625-a6b4-431c-8de8-081f8042c757%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django admin objectaction confirmation

2016-01-19 Thread 张超
Sorry to trouble you again!  
I want to override the change_from.html included in the pacakage 
django_object_actions/templates/django_object_actions/  ...I copy the  
change_from.html and put it in my app directory- 
myapp/templates/admin/django_object_actions/ ,then I add my code...but it 
can't work!
在 2016年1月19日星期二 UTC+8下午3:14:49,Andréas Kühne写道:
>
> Hi,
>
> Check how actions work in the admin interface. You should be able to 
> create something that works the same by clicking on a button. See here: 
> https://docs.djangoproject.com/en/1.9/ref/contrib/admin/actions/
>
> The main point is that if you do a http get, you should show the 
> confirmation page, and if you do a post, the action should happen.
>
> Regards,
>
> Andréas
>
> 2016-01-19 6:53 GMT+01:00 张超 >:
>
>> I want to make a confirmation before executing the objectaction when 
>> click the objectaction button ...I have tried to write a js to do that ,but 
>> it doesn't work..how could I make it?
>>
>> -- 
>> 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/a718b7d5-813c-4706-8bee-1941c078fba9%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/002e1f26-fa67-4299-851c-ee9a1099cd30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.