-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-django
]: Implement rule DJ012 (#3659)
- Loading branch information
1 parent
5eae3fb
commit 9e61956
Showing
14 changed files
with
377 additions
and
23 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
crates/ruff/resources/test/fixtures/flake8_django/DJ012.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
from django.db import models | ||
from django.db.models import Model | ||
|
||
|
||
class StrBeforeRandomField(models.Model): | ||
"""Model with `__str__` before a random property.""" | ||
|
||
class Meta: | ||
verbose_name = "test" | ||
verbose_name_plural = "tests" | ||
|
||
def __str__(self): | ||
return "" | ||
|
||
random_property = "foo" | ||
|
||
|
||
class StrBeforeFieldModel(models.Model): | ||
"""Model with `__str__` before fields.""" | ||
|
||
class Meta: | ||
verbose_name = "test" | ||
verbose_name_plural = "tests" | ||
|
||
def __str__(self): | ||
return "foobar" | ||
|
||
first_name = models.CharField(max_length=32) | ||
|
||
|
||
class ManagerBeforeField(models.Model): | ||
"""Model with manager before fields.""" | ||
|
||
objects = "manager" | ||
|
||
class Meta: | ||
verbose_name = "test" | ||
verbose_name_plural = "tests" | ||
|
||
def __str__(self): | ||
return "foobar" | ||
|
||
first_name = models.CharField(max_length=32) | ||
|
||
|
||
class CustomMethodBeforeStr(models.Model): | ||
"""Model with a custom method before `__str__`.""" | ||
|
||
class Meta: | ||
verbose_name = "test" | ||
verbose_name_plural = "tests" | ||
|
||
def my_method(self): | ||
pass | ||
|
||
def __str__(self): | ||
return "foobar" | ||
|
||
|
||
class GetAbsoluteUrlBeforeSave(Model): | ||
"""Model with `get_absolute_url` method before `save` method. | ||
Subclass this directly using the `Model` class. | ||
""" | ||
|
||
def get_absolute_url(self): | ||
pass | ||
|
||
def save(self): | ||
pass | ||
|
||
|
||
class ConstantsAreNotFields(models.Model): | ||
"""Model with an assignment to a constant after `__str__`.""" | ||
|
||
first_name = models.CharField(max_length=32) | ||
|
||
class Meta: | ||
verbose_name = "test" | ||
verbose_name_plural = "tests" | ||
|
||
def __str__(self): | ||
pass | ||
|
||
MY_CONSTANT = id(1) | ||
|
||
|
||
class PerfectlyFine(models.Model): | ||
"""Model which has everything in perfect order.""" | ||
|
||
first_name = models.CharField(max_length=32) | ||
last_name = models.CharField(max_length=32) | ||
objects = "manager" | ||
|
||
class Meta: | ||
verbose_name = "test" | ||
verbose_name_plural = "tests" | ||
|
||
def __str__(self): | ||
return "Perfectly fine!" | ||
|
||
def save(self, **kwargs): | ||
super(PerfectlyFine, self).save(**kwargs) | ||
|
||
def get_absolute_url(self): | ||
return "http://%s" % self | ||
|
||
def my_method(self): | ||
pass | ||
|
||
@property | ||
def random_property(self): | ||
return "%s" % self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.