We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
不好意思,python新手,這邊有個概念不是很懂: class MusicSerializer(serializers.ModelSerializer): days_since_created = serializers.SerializerMethodField() def get_days_since_created(self, obj): return (now() - obj.created).days
我的理解是class MusicSerializer 繼承了serializers.ModelSerializer ,然後他利用他底下的method get_days_since_created 去回傳一個值。 物件obj 則是呼叫了music。 不理解的地方: 這個def 裡面放了參數obj,但我沒看到其他地方有呼叫這個method,他是怎麼可以運行的?
The text was updated successfully, but these errors were encountered:
@ekils 用中斷點下去看會比較清楚,他是在 Serializer 的時候觸發的
Sorry, something went wrong.
No branches or pull requests
不好意思,python新手,這邊有個概念不是很懂:
class MusicSerializer(serializers.ModelSerializer):
days_since_created = serializers.SerializerMethodField()
def get_days_since_created(self, obj):
return (now() - obj.created).days
我的理解是class MusicSerializer 繼承了serializers.ModelSerializer ,然後他利用他底下的method get_days_since_created 去回傳一個值。
物件obj 則是呼叫了music。
不理解的地方:
這個def 裡面放了參數obj,但我沒看到其他地方有呼叫這個method,他是怎麼可以運行的?
The text was updated successfully, but these errors were encountered: