我有一个模特
models.py
import pygame
import sys
import math
from pygame.locals import *
pygame.init()
WINDOW = pygame.display.set_mode((900, 700))
keys=pygame.key.get_pressed()
y=100
z=100
x=100
FPS=70
fpsClock=pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
keys=pygame.key.get_pressed()
if keys[pygame.K_d]:#Moves character right
y=y+3
if y > 900:
y=900
if keys[pygame.K_a]:#Moves character left
y=y-3
if y<0:
y=0
if keys[pygame.K_s]:#Moves character downwards
z=z+3
if z>700:
z=700
if keys[pygame.K_w]:#Moves character upwards
z=z-3
if z<0:
z=0
if keys[pygame.K_SPACE]:
pygame.draw.rect(WINDOW,COLOUR3,(y+35,z+7,5,2),2)
COLOUR2 = (32,59,202)#Colour of player character
COLOUR = (0,180,0)#Window colour
COLOUR3 =(1,234,254)#Colour of bullet and gun for the player character
WINDOW.fill(COLOUR)#Fills window with the COLOUR variable
pygame.display.update()
pygame.draw.circle(WINDOW, COLOUR2, (y, z), 20)#player character shape
pygame.draw.rect(WINDOW,COLOUR3,(y+10,z+5,25,8), 7)#Part of the player character's weapon
pygame.draw.rect(WINDOW,COLOUR3,(y+35,z+7,10,4), 5#Part of the player character's weapon)
if keys[pygame.K_SPACE]:#Allows player character to shoot bullets
x=x+5 # Speed of bullet
pygame.draw.rect(WINDOW,COLOUR3,(y+35+x,z+7,5,2),2)#Bullet shape
pygame.display.update()
fpsClock.tick(FPS)
我的models.py
的所有对象class EmployeeModel(models.Model):
Employee_id = models.CharField(max_length=200)
name = models.CharField(max_length=200)
basic_salary = models.IntegerField(blank=True,default=0)
HRA = models.IntegerField(blank=True,default=0)
DA = models.IntegerField(blank=True,default=0)
TA = models.IntegerField(blank=True,default=0)
CCA = models.IntegerField(blank=True,default=0)
Medical = models.IntegerField(blank=True,default=0)
bonus = models.IntegerField(blank=True,default=0)
advance_pay = models.IntegerField(blank=True,default=0)
PF = models.IntegerField(blank=True,default=12)
def __str__(self):
return self.name
对于模型&#39; EmployeeModel&#39;的每个实例,我想从字段中检索数据以进一步计算在views.py&#39;为工资总额!例如,我想单独获取字段TA,DA,HRA的数据,以便我可以添加它们。但我不知道如何从Django字段获取数据。我是Django的新手。
答案 0 :(得分:0)
@Lemayzeur感谢先生对于针对性的回答,作为新手很难理解django手册的深度,根据你现在的答案,我可以完成我的项目。我像这样实施
query = employeeModel.objects.values_list('basic_salary', 'DA', 'TA', 'HRA', 'CCA', 'Medical', 'bonus', 'advance_pay',
'PF','PT','leave','working_days').filter(employee_id=employee_id)[0]
print(query)
basic_salary = query[0]
dearness_allowance = query[1]
travel_allowance = query[2]
house_rent_allowance = query[3]
city_compensatory_allowance = query[4]
medical_allowance = query[5]
bonus = query[6]
advance_pay = query[7]
provident_fund = query[8]
professional_tax = query[9]
leave = query[10]
working_days = query[11]
我知道,它不是动态的,检索数据通常是开发人员使用我将要学习的API和ajax。