--
Ticket URL: <https://code.djangoproject.com/ticket/25478>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_better_patch: => 0
* resolution: => worksforme
* needs_tests: => 0
* needs_docs: => 0
Comment:
Just tried an expression like this in a shell and apparently the parens
are not mandatory in this case.
{{{
>>> lst = [1, 2, 3, 'a']
>>> print([
... item
... for item in lst
... if item > 0
... and item != 'a'
... ])
[1, 2, 3]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25478#comment:1>
* status: closed => new
* resolution: worksforme =>
Comment:
I didn't mean that it was a syntax error. I meant that the logic was
wrong. Without the parens, the condition is equivalent to:
{{{
(not f.is_relation) or (f.one_to_one) or (f.many_to_one and
f.related_model)
}}}
Don't we actually want:
{{{
not (f.is_relation or f.one_to_one or (f.many_to_one and f.related_model))
}}}
That is, the field should be excluded if it's a relation or if it's one-
to-one, or if it's both many-to-one and related.
--
Ticket URL: <https://code.djangoproject.com/ticket/25478#comment:2>
* cc: pirosb3@… (added)
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Oh, sorry for misunderstanding! I think you are right.
--
Ticket URL: <https://code.djangoproject.com/ticket/25478#comment:3>
Comment (by timgraham):
It looks correct to me. The idea seems to be to exclude all relations
except foreign keys and one-to-one fields. Here's an example from
djangoproject.com where you can see those fields included in the old API:
{{{
>>> from accounts.models import Profile
>>> Profile._meta.get_fields_with_model()
[(<django.db.models.fields.AutoField: id>, None),
(<django.db.models.fields.related.OneToOneField: user>, None),
(<django.db.models.fields.CharField: name>, None)]
}}}
Can you provide an example discrepancy?
--
Ticket URL: <https://code.djangoproject.com/ticket/25478#comment:4>
Comment (by PirosB3):
It looks correct to me too. To make sure we could also write an automated
test for it if there isn't one already.
--
Ticket URL: <https://code.djangoproject.com/ticket/25478#comment:5>
* status: new => closed
* resolution: => worksforme
--
Ticket URL: <https://code.djangoproject.com/ticket/25478#comment:6>