mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -12,15 +12,15 @@ class User(models.Model):
|
||||
|
||||
class Issue(models.Model):
|
||||
num = models.IntegerField()
|
||||
cc = models.ManyToManyField(User, blank=True, related_name='test_issue_cc')
|
||||
client = models.ForeignKey(User, models.CASCADE, related_name='test_issue_client')
|
||||
cc = models.ManyToManyField(User, blank=True, related_name="test_issue_cc")
|
||||
client = models.ForeignKey(User, models.CASCADE, related_name="test_issue_client")
|
||||
|
||||
class Meta:
|
||||
ordering = ('num',)
|
||||
ordering = ("num",)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.num)
|
||||
|
||||
|
||||
class StringReferenceModel(models.Model):
|
||||
others = models.ManyToManyField('StringReferenceModel')
|
||||
others = models.ManyToManyField("StringReferenceModel")
|
||||
|
||||
@@ -5,9 +5,8 @@ from .models import Issue, StringReferenceModel, User
|
||||
|
||||
|
||||
class RelatedObjectTests(TestCase):
|
||||
|
||||
def test_related_objects_have_name_attribute(self):
|
||||
for field_name in ('test_issue_client', 'test_issue_cc'):
|
||||
for field_name in ("test_issue_client", "test_issue_cc"):
|
||||
obj = User._meta.get_field(field_name)
|
||||
self.assertEqual(field_name, obj.field.related_query_name())
|
||||
|
||||
@@ -30,54 +29,59 @@ class RelatedObjectTests(TestCase):
|
||||
i3.cc.add(r)
|
||||
|
||||
self.assertQuerysetEqual(
|
||||
Issue.objects.filter(client=r.id), [
|
||||
Issue.objects.filter(client=r.id),
|
||||
[
|
||||
1,
|
||||
2,
|
||||
],
|
||||
lambda i: i.num
|
||||
lambda i: i.num,
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Issue.objects.filter(client=g.id), [
|
||||
Issue.objects.filter(client=g.id),
|
||||
[
|
||||
3,
|
||||
],
|
||||
lambda i: i.num
|
||||
lambda i: i.num,
|
||||
)
|
||||
self.assertQuerysetEqual(Issue.objects.filter(cc__id__exact=g.id), [])
|
||||
self.assertQuerysetEqual(
|
||||
Issue.objects.filter(cc__id__exact=g.id), []
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Issue.objects.filter(cc__id__exact=r.id), [
|
||||
Issue.objects.filter(cc__id__exact=r.id),
|
||||
[
|
||||
2,
|
||||
3,
|
||||
],
|
||||
lambda i: i.num
|
||||
lambda i: i.num,
|
||||
)
|
||||
|
||||
# These queries combine results from the m2m and the m2o relationships.
|
||||
# They're three ways of saying the same thing.
|
||||
self.assertQuerysetEqual(
|
||||
Issue.objects.filter(Q(cc__id__exact=r.id) | Q(client=r.id)), [
|
||||
Issue.objects.filter(Q(cc__id__exact=r.id) | Q(client=r.id)),
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
lambda i: i.num
|
||||
lambda i: i.num,
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Issue.objects.filter(cc__id__exact=r.id) | Issue.objects.filter(client=r.id), [
|
||||
Issue.objects.filter(cc__id__exact=r.id)
|
||||
| Issue.objects.filter(client=r.id),
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
lambda i: i.num
|
||||
lambda i: i.num,
|
||||
)
|
||||
self.assertQuerysetEqual(
|
||||
Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)), [
|
||||
Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)),
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
],
|
||||
lambda i: i.num
|
||||
lambda i: i.num,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user