小编Akh*_*ahu的帖子

将组件选择器用于 Angular 4 中的其他组件

我需要将滑块组件添加到主页组件。

滑块组件是

滑块.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-slider',
  templateUrl: './slider.component.html',
  styleUrls: ['./slider.component.css']
})
export class SliderComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)
 
Run Code Online (Sandbox Code Playgroud)

滑块.component.html

<div class="container-image-slider">
         <img id="img1">
          <img id="img2">
          <img id="img3">
  </div>
Run Code Online (Sandbox Code Playgroud)

主页组件 home.component.ts

import { Component, OnInit } from '@angular/core';
 @Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

主页.component.html

<app-slider></app-slider>
Run Code Online (Sandbox Code Playgroud)

这里的问题是它给出了错误

<app-slider></app-slider>
Run Code Online (Sandbox Code Playgroud)

html angular

1
推荐指数
1
解决办法
5428
查看次数

在表中执行 JOIN django

在 django 中执行 JOIN 以反向关系获取相关日期。共有三种型号。

以下是模型的代码

class Question(models.Model):
	title = models.CharField(max_length=255 )
	description = models.TextField(max_length=300)
  

class Quiz(models.Model):
	name = models.CharField(max_length=225,blank=False )
	quiz_type =models.IntegerField(choices=QUIZ_TYPE,default=0)
    questions = models.ManyToManyField( Question, through='QuestionQuiz', related_name="quiz_question") 
	categories= models.ManyToManyField(Category,through='CategoryQuiz',related_name='quiz_category')		
 

class QuestionQuiz(models.Model):
	quiz = models.ForeignKey(Quiz,on_delete=models.CASCADE)
	question = models.ForeignKey(Question,on_delete=models.CASCADE)	
	correct =models.DecimalField(max_digits=4, decimal_places=3)
    incorrect= models.DecimalField(max_digits=4, decimal_places=3) 

	class Meta:
		unique_together = ('quiz','question')
Run Code Online (Sandbox Code Playgroud)

在这种情况下,使用模型问题测验将问题添加到测验中。

在这里, QuizQuestion 与问题具有外键关系。我需要从问题 JOIN 中获取所有内容,并使用特定的 quiz_id 从 QuestionQuiz 中获取记录。

假设 quiz_id =3 然后我将获取所有正确和不正确的问题。如果该测验 ID 被添加到问题中,那么它将显示正确的不正确,否则这些将是空白的。

question_id | title|description|correct|incorrect|quesquizid
1 | Q1 |Q1desc |2 | -2 | 1 2 | …

python django

1
推荐指数
1
解决办法
37
查看次数

使用 Django Rest 在多级嵌套序列化器中获取数据

需要序列化三个层次嵌套的三个模型。有用户分配的区域,这些区域包含点。用户包含多个区域。区域有多个关联点。用户使用多对多关系链接区域。Areas 在点中使用 Foreign 与点链接。用户可以分配到多个区域。区域可以有多个点。

用户配置文件模型

class UserProfile(AbstractBaseUser,PermissionsMixin):
      phone_number= PhoneNumberField( unique=True)
      name=models.CharField(max_length=255)
      organisation=models.CharField(max_length=255)
      is_active=models.BooleanField(default=True)
      is_staff=models.BooleanField(default=False)
      added_by=models.ForeignKey(settings.AUTH_USER_MODEL,default=1)  
      group = models.ForeignKey('auth.Group', null=True)
      areas=models.ManyToManyField('area.Area',blank=True)
      objects=UserProfileManager()
Run Code Online (Sandbox Code Playgroud)

区域模型

from django.db import models
from django.conf import settings

 # Create your models here.
class Area(models.Model):
      areaName =models.TextField()
      timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
      updated = models.DateTimeField(auto_now=True, auto_now_add=False)
      user = models.ForeignKey(settings.AUTH_USER_MODEL )
      def __str__(self):
         return self.areaName 
Run Code Online (Sandbox Code Playgroud)

点模型

from django.db import models

from django.conf import settings

# Create your models here.
class Point(models.Model):
    name =models.TextField()
    area = models.ForeignKey('area.Area', on_delete=models.CASCADE)
    latitude=models.CharField(max_length=200)
    longitude=models.CharField(max_length=200)
    timestamp=models.DateTimeField(auto_now=False,auto_now_add=True) …
Run Code Online (Sandbox Code Playgroud)

django-rest-framework

0
推荐指数
1
解决办法
1157
查看次数

标签 统计

angular ×1

django ×1

django-rest-framework ×1

html ×1

python ×1