如何在床铺分配给Django的患者时自动选择患者姓名字段

时间:2017-02-08 13:51:40

标签: django

如何为患者Django分配病床?

当我尝试在bedconfig中为病人分配病床时,自动选择患者姓名

然后打开wardconfig文件,但患者姓名是blant,必须自动选择患者姓名

查看此图片When click on assign bed

but Patient name is blant, it must be autoselected Patient name

  

models.py患者模型

class Patient(Auditable):
aadhar_no = models.CharField(max_length=12, blank=True,unique=True)
fullname = models.CharField(max_length=50) 
firstname = models.CharField(max_length=30)
middlename = models.CharField(max_length=30)
lastname = models.CharField(max_length=30)

CATEGORY_GENDER= (('Male', 'Male'), ('Female', 'Female'))
gender = models.CharField(max_length=6, choices=CATEGORY_GENDER)
CATEGORY_BG= (('Not known','Not known'),('A+', 'A+'), ('A-', 'A-'),('B+', 'B+'),('B-', 'B-'),('AB+', 'AB+'),('AB-','AB-'),('O+','O+'), ('O-','O-'))
blood_group = models.CharField(max_length=10, choices=CATEGORY_BG)
dob = models.DateField()  #Date of birth
photo = models.ImageField(upload_to="Patient/", null=True, blank=True)
education = models.CharField(max_length=15, null=True, blank=True)
CATEGORY_OCC= (('Service', 'Service'), ('Retired', 'Retired'),('Housewife', 'Housewife'), ('Business','Business'),('other','other'))
occupation = models.CharField(max_length=15, choices=CATEGORY_OCC,null=True, blank=True) #service, retired, Housewife, Business, others 
current_address = models.TextField()
mobile_number = models.CharField(max_length=12)
mobile_number2 = models.CharField(max_length=12, null=True, blank=True)
phone_number = models.CharField(max_length=12, null=True, blank=True)
email = models.CharField(max_length=30, null=True, blank=True)
country = models.ForeignKey(Country , null=True, blank=True, )
state = models.ForeignKey(State , null=True, blank=True)
district = models.ForeignKey(District , null=True, blank=True)
city = models.ForeignKey(City ,null=True, blank=True)
recreational_drugs= models.BooleanField(default=False) #alocohol, smoking,coffine etc.
current_insurance = models.BooleanField(default=False)
#family = models.ForeignKey(Family) # Family
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):  # __unicode__ on Python 2
   # return self.fullname
    return str(self.fullname) 
class Meta:
    verbose_name_plural = "Patient"
  

models.py WardConfog

class WardConfig(Auditable):
bed = models.ForeignKey(Bed)
ward = models.ForeignKey(Ward)
patient=models.ForeignKey(Patient)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
#def __str__(self):  # __unicode__ on Python 2
    #return self.name
class Meta:
    verbose_name_plural = "Wardconfig"
  

Views.py PatientCreate(CreateView)

class PatientCreate(CreateView):     model =病人     form_class = PatientForm

def get_success_url(self): 
    return reverse_lazy( 'patient')

def form_valid(self,PatientForm):
    PatientForm.save()
    return HttpResponseRedirect(self.get_success_url())

def form_invalid(self, PatientForm):
    return self.render_to_response(self.get_context_data(form=PatientForm))
  

Views.py

class WardConfig(Auditable):
bed = models.ForeignKey(Bed)
ward = models.ForeignKey(Ward)
patient=models.ForeignKey(Patient)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
#def __str__(self):  # __unicode__ on Python 2
    #return self.name
class Meta:
    verbose_name_plural = "Wardconfig"

请帮助我如何在分配病床时自动选择Wardconfig中的患者姓名

抱歉英语

1 个答案:

答案 0 :(得分:1)

您可以使用urlpatterns = [ url(r'^upload', UploadVideo.as_view(), name='upload'), url(r'^(?P<pk>[0-9]+)/$', VideoView.as_view(), name='videoview'), url(r'^(?P<pk>[0-9]+)/ratings', RatingView.as_view(success_url='success_yea'), name='rating_view'), url(r'^success', upload, name='success_yea') ] 方法添加WardConfig记录。这假设您在URL中传递了patient_id kwarg:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <configuration>
                <tasks>
                    <mkdir dir="target/generated-sources/scalabuff" />
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>protobuf-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
          <argument>-classpath</argument>
          <!-- automatically creates the classpath using all project dependencies,
           also adding the project build directory -->
          <classpath/>
          <argument>net.sandrogrzicic.scalabuff.compiler.ScalaBuff</argument>
            <argument>--proto_path=src/main/protobuf</argument>
            <argument>--scala_out=target/generated-sources/scalabuff</argument>
        </arguments>
        <sourceRoot>target/generated-sources/scalabuff</sourceRoot>
    </configuration>
</plugin>