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
Anybody have experience with a Max Recursion error when using defer? | |
https://dpaste.org/1o8W -- This code will work as-is, I've ran into a Max Recursion error when __init__ has TWO fields it's trying to access | |
https://dpaste.org/bdXc -- here is the code that errors, I've removed the comment in Person.__init__ and now there are TWO fields it's trying to access vs ONE | |
I guess I'm more asking to help understand why ONE vs TWO fields causes the recursion error. I see refresh_from_db getting called and from the docs I've read it makes sense because it does that for the field that it doesn't have (first_name), then in the __init__ it looks like it is calling "only" with the field "has_siblings" | |
Then looks like it's trying to call refresh_from_db on the second field in the __init__ "suffix" with deferred fields having "has_siblings" | |
If anybody could confirm that analysis and if this is intended behavior and just poor performance OR if this appears to be an actual bug and I should open a ticket for it? | |
Here is a prof |
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
from django.utils.translation import gettext_lazy as _ | |
class Game(models.Model): | |
TEEBALL_INTRODUCED_VERSION = "1.1.0" | |
REVAMPED_PRODUCT_INTRODUCED_VERSION = "2.0.0" | |
class GameType(models.TextChoices): | |
BASEBALL = "BB", _("Baseball") | |
SOFTBALL = "SB", _("Softball") |
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
from rest_framework import viewsets | |
class GameViewSet(viewsets.ReadOnlyModelViewSet): | |
"""Game viewset.""" | |
queryset = Game.objects.all() | |
serializer_class = GameSerializer | |
def get_serializer_class(self): | |
"""Determine serializer class.""" |
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
from rest_framework import viewsets | |
class GameViewSet(viewsets.ReadOnlyModelViewSet): | |
"""Game viewset.""" | |
queryset = Game.objects.all() | |
serializer_class = GameSerializer | |
def get_queryset(self): | |
"""Filter class queryset.""" |
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
from rest_framework import viewsets | |
from semantic_version import SimpleSpec, Version | |
class GameViewSet(viewsets.ReadOnlyModelViewSet): | |
"""Game viewset.""" | |
queryset = Game.objects.all() | |
serializer_class = GameSerializer | |
def get_queryset(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
from django.utils.translation import gettext_lazy as _ | |
class Game(models.Model): | |
TEEBALL_INTRODUCED_VERSION = "1.1.0" | |
class GameType(models.TextChoices): | |
BASEBALL = "BB", _("Baseball") | |
SOFTBALL = "SB", _("Softball") | |
TEEBALL = "TB", _("Tee-ball") |
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
from django.utils.translation import gettext_lazy as _ | |
class Game(models.Model): | |
class GameType(models.TextChoices): | |
BASEBALL = "BB", _("Baseball") | |
SOFTBALL = "SB", _("Softball") | |
type = models.CharField( | |
max_length=2, |
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
def get_serializer_class(self): | |
if self.request.version in ['v1', 'v2']: | |
return AccountSerializerVersion1 | |
return AccountSerializer |
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
def get_serializer_class(self): | |
if self.request.version == 'v1': | |
return AccountSerializerVersion1 | |
return AccountSerializer |
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
Show hidden characters
{ | |
"folders": [ | |
{ | |
"path": "." | |
} | |
], | |
"settings": { | |
"python.pythonPath": "<path-to-env>" | |
} | |
} |
NewerOlder