Re: ORM and admin

2014-04-09 Thread 沈世军


在 2014年4月2日星期三UTC+8上午12时26分17秒,Pradip Caulagi写道:
>
> It is rather late in the day to bring this up but ... 
>
> should we remove ORM and admin from Django core? 
>
> Thanks, 
> Pradip P Caulagi 


I do not think that orm and admin should be removed,but we should improve 
it. 

>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/c3d9e3cd-c959-4eaa-b4ad-6e4390d9f0eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Should there be a "is" comperator: {% if A is B %}?

2014-04-09 Thread Gregor Müllegger
Hi,

I recently had the need to check for "value is not True" (as an identity
check, not
on equality) in django-floppyforms. The template should generate the HTML
attributes for an HTML element from a python dict, but leave out the
attribute
value if the dict's value is True. Like:

  {'required': True, 'name': 'fieldname'} => 

If there would be an "is" identity check in the Django template language it
would look like:

{% for name, value in attrs.items %} {{ name }}{% if value is not True
%}="{{ value }}"{% endif %}{% endfor %}

But since there is none, the if case looks now like this:

{% if value|stringformat:"s" != "True" or value != 1 %}

See:
https://github.com/gregmuellegger/django-floppyforms/blob/master/floppyforms/templates/floppyforms/attrs.html

The template previously checked with {% if not value %}, but that would
break if
you pass in the integer 1. Since "True == 1", but "True is not 1".


I do get why there is no "is" comperator in the DTL yet. It might be
confused
with the equality check by designers that don't know the underlying
concepts of
equality and identity. And I think that's totally reasonable.

However I still want to bring this up since there is this real usecase I
described above. Ofcourse I could introduce a custom filter or tag to
scratch
that itch, but IMO this is something very fundamental that I would expect
to have
as a python developer.

So here are a few solutions I can think of:

1. Have an "is" and "is not" comperator in the {% if %} tag. Could lead to
confusion.

2. Have a "===" and "!==" comperator in the {% if %} tag. This is something
nearer to
   Javascript than python and makes it clear that it's different to == but
would
   still confuse someone who did't read the DTL documentation.

3. Have a "is_identical" builtin filter. So it would be {% if not
value|is_identical:True %}.


My favourite is option 3. It's very readable and doesn't introduce possible
confusions for non-python programmers.

What is your opinion on this?


Gregor

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