django-测验app,如何跟踪所有用户的选择

时间:2017-01-08 10:00:00

标签: django

注册用户,选择问题的答案。

我需要保存每个用户选择的选项(答案)

models.py

public class Bersaglio extends JComponent implements MouseListener  {

Ellipse2D.Double circle;
Ellipse2D.Double circle1;
Ellipse2D.Double circle2;
Ellipse2D.Double circle3;
/*public void setup(){
    x=0;
    y=0;        
}
/*Color c;
int hight;
int weight;


public Circle() {
    super();
}
public Circle(int x,int y,int hight,int weight) {
    this.x=x;
    this.y=y;
    this.hight=hight;
    this.weight=weight;
} */
public void paintComponent(Graphics g){
    Graphics2D g2;
    g2 = (Graphics2D) g;
    g2.setColor(Color.BLUE);
    circle1 = new Ellipse2D.Double(30, 30, 100, 100);
    g2.fill(circle1);
    //c1.fillOval(30,30,100,100);

    //secondo cerchio medio
    g2.setColor(Color.RED);
    circle2 = new Ellipse2D.Double(50,50,60,60);
    g2.fill(circle2);
    //c1.fillOval(50,50,60,60);

    //terzo cerchio piccolo
    g2.setColor(Color.BLACK);
    circle3 = new Ellipse2D.Double(70,70,20,20);
    g2.fill(circle3);
    //c1.fillOval(70,70,20,20);
    addMouseListener(this);

    //scrivere qualcosa
    //g2.drawString("Ciao", 50, 100);
}

public void mouseClicked (MouseEvent e) {
    //x = e.getX();
    //y = e.getY();
     Point p = e.getPoint();
     if(circle3.contains(p)) {
         System.out.println("Circle3 contains point");
     }else{ 
        if(circle2.contains(p)) { 
            System.out.println("Circle2 contains point");
        }else {
            if(circle1.contains(p)) {
                 System.out.println("Circle1 contains point");
            }
        }
     }
     Graphics g = getGraphics();
     Graphics2D g2 = (Graphics2D) g;
     circle = new Ellipse2D.Double(p.getX(),p.getY(),10,10);
     g2.fill(circle);
     revalidate();

} 
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}

创建Question对象时:

如何使用新创建的问题填充状态模型中的每个用户,反之亦然

实施例

我有5个问题。当我添加新用户时,状态模型应该将所有问题链接到用户

OR

添加新问题时,状态模型应将所有用户链接到问题

https://github.com/garrykevin-ep/codewars

1 个答案:

答案 0 :(得分:0)

问题是我在用SQL方式思考,而不是Django方式

当我登录用户时

def s_pop(request):
    current_user = request.user
    qlist = Question.objects.all()
    for x in qlist:
        Status.objects.get_or_create(User = current_user,question = x)
    return HttpResponseRedirect(reverse('quiz:ans',args = (first_question(),)))

然后我重定向到第一个问题。