Skip to content

Update models.py #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 17 additions & 39 deletions testapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db.models import Q
from django.utils import timezone


# We are using this Mixin to test casting of BigAuto and Auto fields
class BigAutoFieldMixin(models.Model):
id = models.BigAutoField(primary_key=True)
Expand All @@ -31,9 +32,7 @@ class Post(BigAutoFieldMixin, models.Model):
alt_editor = models.ForeignKey(Editor, models.SET_NULL, blank=True, null=True)

class Meta:
unique_together = (
('author', 'title', 'alt_editor'),
)
unique_together = (('author', 'title', 'alt_editor'), )

def __str__(self):
return self.title
Expand Down Expand Up @@ -73,7 +72,7 @@ class TestUniqueNullableModel(models.Model):

class TestNullableUniqueTogetherModel(models.Model):
class Meta:
unique_together = (('a', 'b', 'c'),)
unique_together = (('a', 'b', 'c'), )

# Issue https://github.com/ESSolutions/django-mssql-backend/issues/45 (case 2)
# Fields used for testing changing the type of a field that is in a `unique_together`
Expand Down Expand Up @@ -119,43 +118,28 @@ class Pizza(models.Model):
toppings = models.ManyToManyField(Topping)

def __str__(self):
return "%s (%s)" % (
self.name,
", ".join(topping.name for topping in self.toppings.all()),
)
return "%s (%s)" % (self.name, ", ".join(topping.name for topping in self.toppings.all()), )


class TestUnsupportableUniqueConstraint(models.Model):
class Meta:
managed = False
constraints = [
models.UniqueConstraint(
name='or_constraint',
fields=['_type'],
condition=(Q(status='in_progress') | Q(status='needs_changes')),
),
]
constraints = [models.UniqueConstraint(name='or_constraint',
fields=['_type'],
condition=(Q(status='in_progress') | Q(status='needs_changes')), ), ]

_type = models.CharField(max_length=50)
status = models.CharField(max_length=50)


class TestSupportableUniqueConstraint(models.Model):
class Meta:
constraints = [
models.UniqueConstraint(
name='and_constraint',
fields=['_type'],
condition=(
Q(status='in_progress') & Q(status='needs_changes') & Q(status='published')
),
),
models.UniqueConstraint(
name='in_constraint',
fields=['_type'],
condition=(Q(status__in=['in_progress', 'needs_changes'])),
),
]
constraints = [models.UniqueConstraint(name='and_constraint',
fields=['_type'],
condition=(Q(status='in_progress') & Q(status='needs_changes') & Q(status='published')), ),
models.UniqueConstraint(name='in_constraint',
fields=['_type'],
condition=(Q(status__in=['in_progress', 'needs_changes'])), ), ]

_type = models.CharField(max_length=50)
status = models.CharField(max_length=50)
Expand All @@ -178,15 +162,9 @@ class TestCheckConstraintWithUnicode(models.Model):
name = models.CharField(max_length=100)

class Meta:
required_db_features = {
'supports_table_check_constraints',
}
constraints = [
models.CheckConstraint(
check=~models.Q(name__startswith='\u00f7'),
name='name_does_not_starts_with_\u00f7',
)
]
required_db_features = {'supports_table_check_constraints', }
constraints = [models.CheckConstraint(check=~models.Q(name__startswith='\u00f7'),
name='name_does_not_starts_with_\u00f7', )]


class Question(models.Model):
Expand Down Expand Up @@ -229,4 +207,4 @@ class Number(models.Model):
decimal_value = models.DecimalField(max_digits=20, decimal_places=17, null=True)

def __str__(self):
return "%i, %.3f, %.17f" % (self.integer, self.float, self.decimal_value)
return "%i, %.3f, %.17f" % (self.integer, self.float, self.decimal_value)