我有以下2个序列化器:
class BasicSerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = ('lengthy', 'touple', 'of', \
'fields', 'like', '10', 'of', 'them')
class AdvandedSerializer(BasicSerializer):
additional_field = serializers.SerializerMethodField()
def get_additional_field(self, obj):
return('not important')
class Meta:
model = MyModel
fields = ('lengthy', 'touple', 'of', \
'fields', 'like', '10', 'of', 'them', 'additional_field')
Run Code Online (Sandbox Code Playgroud)
这显然是难看的代码。我想从中获取和扩展fields
touple super()
,但是我不知道如何。
我有一个基于其道具的组件,使用几乎相同的道具呈现另一个组件,如下所示:
render() {
return(
<Component>
{this.renderComponent()}
</Component>
)
renderComponent() {
switch (condition) {
case "A": {
return (
<ComponentA
many={...}
same={...}
things={...}
oneDifferentProp="A"
/>
}
case "B": {
return (
<WrapperComponent>
<ComponentB
many={...}
same={...}
things={...}
oneDifferentProp="B"
/>
<SomethingOther>
</WrapperComponent>
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
那么我该如何使它更好,可扩展且易读?
我想让应用程序记住用户在关闭手机后放入的一些数据(如自动登录).怎么能在React Native中完成?或者我应该研究哪些库/组件?
我有一个看起来像这样的分支
---A-----------B
\
\
C (Detached HEAD)
Run Code Online (Sandbox Code Playgroud)
我通过这个过程得到了它:
git checkout branch
git checkout HEAD~
git commit -m "C"
Run Code Online (Sandbox Code Playgroud)
我想C
覆盖B
(放弃B中的所有更改)
最好是不合并临时分支,因为我希望分支图看起来尽可能简单