我有一个名为的抽象模型类,PostType并有一些从中派生的子模型。该模型如下所示:
class PostType(models.Model):
title = models.CharField(
max_length=255,
unique=True,
verbose_name='Title'
)
description = models.CharField(
max_length=255,
default='',
verbose_name='Description'
)
tags = models.ManyToManyField(
to=Tag,
blank=True,
verbose_name='Tags'
)
content = RichTextUploadingField(
default='',
verbose_name='Post Content'
)
class Meta:
abstract = True
Run Code Online (Sandbox Code Playgroud)
它有一个相关的标签模型,如下所示:
class Tag(models.Model):
name = models.CharField(
max_length=255,
verbose_name='Name',
unique=True
)
description = models.TextField(
verbose_name='Description',
default=''
)
Run Code Online (Sandbox Code Playgroud)
在我的一种观点中,我尝试使用 aSearchVector并搜索多个字段来查询所有子类:
query = request.GET.get('s')
from django.contrib.postgres.search import SearchVector
get_qs_list = [model.objects.annotate(
search=SearchVector('title', 'description', 'content', 'tags__name')
).filter(search=query) for model in models.PostType.__subclasses__()]
Run Code Online (Sandbox Code Playgroud)
现在,搜索正在返回所有应有的结果。但是,由于某种原因,它会返回某些项目的重复结果。 …
我有一个仪表板应用程序,在这里我懒惰地加载小部件(与路线无关)。
我通过定义一个对象来做到这一点{name: string, loadChildren: string}。然后app.module我会做的provideRoutes(...)。
这将导致cli为每个小部件模块创建一个块。
然后在运行时,我将使用SystemJsModuleLoader加载该字符串并获取一个NgModuleRef。
使用,我可以创建一个从模块和调用组件createComponent上ViewContainerRef。
这是该函数:
loadWidget(
name: string,
container: ViewContainerRef,
widget: Widget
): Promise<{ instance: WidgetComponent; personlize?: { comp: any; factory: ComponentFactoryResolver } }> {
if (this.lazyWidgets.hasOwnProperty(name)) {
return this.loader.load(this.lazyWidgets[name]).then((moduleFactory: NgModuleFactory<any>) => {
const entryComponent = (<any>moduleFactory.moduleType).entry;
const moduleRef = moduleFactory.create(this.injector);
const compFactory = moduleRef.componentFactoryResolver.resolveComponentFactory(entryComponent);
const comp = container.createComponent(compFactory);
(<WidgetComponent>comp.instance).widget = widget;
const personalize = (<any>moduleFactory.moduleType).personalize;
if (personalize) {
return {
instance: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试捕获图像并将其上传到服务器几天但没有运气。我的客户端使用 Ionic 4,后端使用 Java(我使用 Jersey 将后端暴露给 REST)。
现在,问题是在拍摄图像并尝试上传后,我的后端不断收到空值。
这是我的客户端代码:
openCam(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
cameraDirection: 1
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
//alert(imageData)
this.imageData = imageData;
this.image=(<any>window).Ionic.WebView.convertFileSrc(imageData);
this.isImageCaptureed = true;
}, (err) => {
// Handle error
alert("error "+JSON.stringify(err))
});
}
upload(){
let url = 'http://mydommain/api/upload';
let dataURL = 'data:image/jpeg;base64,' + this.imageData;
let postData …Run Code Online (Sandbox Code Playgroud) 我有一个服务(data.service.ts)和一个组件(page.component.ts)。
在这个 data.service.ts 服务中有一个名为changes$
当我加载页面时,它成功从存储中获取数据并解析(使用 .next())到可观察的数据。
在我的 page.component.ts 组件中,它订阅了这个可观察的内容,以下每个更改都会得到处理,但第一个(页面加载时)不会。
为什么?我的 data.service.ts 在 page.component.ts 订阅此changes$可观察对象之前解析数据(使用 .next())。
“等待”组件被订阅的最佳方式是什么?
我找到了一种解决方法setTimeout(() => { ... }, 0),但感觉不对(如果你明白我的意思)
这是一些代码:
数据.服务.ts:
export class DoorService implements OnDestroy {
private data: DoorServiceData;
private destroy$: Subject<void> = new Subject();
private changesSubject$: Subject<IDoorSettings> = new Subject();
// this way users cannot parse values to the subject. read-only...
public changes$: Observable<IDoorSettings> = this.changesSubject$.asObservable().pipe(takeUntil(this.destroy$));
constructor(){
this.init();
}
// service initializer, set data etc.
private init() {
setTimeout(() => …Run Code Online (Sandbox Code Playgroud) src
|_auth/
|_authentication/
|_auth-service.ts
|_auth-guard.ts
|_is-logged-guard.ts
|_dashboard/
Run Code Online (Sandbox Code Playgroud)
auth-guard-service.ts
src
|_auth/
|_authentication/
|_auth-service.ts
|_auth-guard.ts
|_is-logged-guard.ts
|_dashboard/
Run Code Online (Sandbox Code Playgroud)
auth-guard.ts
export class AuthService {
public user: Observable<firebase.User>;
public userDetails: firebase.User = null;
public userProfileRef: firebase.database.Reference;
userData: any[] = [];
constructor(private _firebaseAuth: AngularFireAuth, private router: Router) {
this.user = _firebaseAuth.authState;
this.userProfileRef = firebase.database().ref('/userProfile');
this.user.subscribe(
(user) => {
if (user) {
this.userDetails = user;
} else {
this.userDetails = null;
}
}
);
}
isLoggedIn() {
if (this.userDetails == null) {
return false;
} else { …Run Code Online (Sandbox Code Playgroud) angular ×4
typescript ×4
asynchronous ×1
django ×1
firebase ×1
ionic4 ×1
jersey ×1
observable ×1
python ×1
python-3.x ×1
rest ×1