我刚刚将我的 python 从 3.9.1 更新到 3.9.4。当我尝试运行服务器时。控制台为此给了我一个警告:
WARNINGS:
learning_logs.Entry: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the LearningLogsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
learning_logs.Topic: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the LearningLogsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
No changes detected in app …Run Code Online (Sandbox Code Playgroud) 我有两个相同型号的序列化器。我想嵌套它们。
不幸的是,这种方法不起作用:
class BookSerializer(serializers.ModelSerializer):
class Meta:
model = Book
fields = ['name', 'word_count']
class BetterBookSerializer(serializers.ModelSerializer):
book = BookSerializer(many=False)
class Meta:
model = Book
fields = ('id', 'book')
Run Code Online (Sandbox Code Playgroud)
预期结果:
{
"id": 123,
"book": {
"name": "book_name",
"word_count": 123
}
}
Run Code Online (Sandbox Code Playgroud) 如何使用 flutter 从图库(相机胶卷)中获取最后一张照片?
我想将这张照片显示为缩略图,如下所示:
我知道在android中可以获取相机拍摄的图片的uri,在IOS中也是可以的 Swift 中,如何从照片库中获取最后拍摄的 3 张照片?
有没有工具、库、媒体 API 可以帮助我解决这个问题?
关闭streamSink后,还需要取消监听吗?
找到这个答案:Dart:我必须取消 Stream 订阅并关闭 StreamSinks 吗?
一般来说,当您听完该 Stream 后,无论出于何种原因,您都应该关闭订阅
那么,如果我不取消订阅,它们就会永远保持开放状态吗?垃圾收集器不会处理它们吗?
StreamController<int> controller = StreamController<int>();
Stream stream = controller.stream;
StreamSubscription subscription = stream.listen((value) {
print('Value from controller: $value');
})
..onDone(() => print('done'));
// prints : Value from controller: 1
controller.add(1);
// prints : done
controller.close();
// still listening to closed stream
// no error - cancels successfully
Future.delayed(Duration(seconds: 2), () => subscription.cancel());
Run Code Online (Sandbox Code Playgroud)