2 different search in a view

GioBot

I have two tables one that stores information from a medical record and the other a second medical consultation, what I want is to make a search and if the patient had a second medical consultation shows me the information of the second medical consultation in my template, if the patient doesn't have a second medical consultation only show me the information of the medical record. I need help and ideas on how I can do it, I'm new with Django and Python , I do the search in a view in the following way, the problem with this search is that I only see the medical record and I need that if the patient had second medical consultation to display the information.

View.py

def Expediente_Detalle(request, credencial):
    Expediente_Detalle = get_object_or_404(ExpedienteConsultaInicial, credencial_consultainicial=credencial)
    return render(request, 'ExpedienteDetalle.html', {'Expediente_Detalle': Expediente_Detalle})

Models.py

class ExpedienteConsultaInicial(models.Model):       
    credencial_consultainicial = models.CharField(max_length=10, null=True, blank=True)

    def __unicode__(self):
        return self.credencial_consultainicial


class ConsultasSubsecuentes(models.Model):
     Consultasbc_credencial    =models.ForeignKey(ExpedienteConsultaInicial,
     related_name='csb_credencial')
Gill Bates

Try:

#Models

class ExpedienteConsultaInicial(models.Model):
    #max_legth=10 might be too small
    credencial_consultainicial = models.CharField(max_length=100, null=True, blank=True)

    def __unicode__(self):
        return self.credencial_consultainicial


class ConsultasSubsecuentes(models.Model):
     #related_name is name of attribute of instance of model 
     #to (not from!) which ForeignKey points.
     #Like:
     #assuming that `related_name` is 'consultations'
     #instance = ExpedienteConsultaInicial.objects.get(
     #                     credencial_consultainicial='text text text'
     #)
     #instaqnce.consultations.all()
     #So I suggest to change `related_name` to something that will explain what data of this model means in context of model to which it points with foreign key.
     consultasbc_credencial = models.ForeignKey(ExpedienteConsultaInicial,
     related_name='consultations')

#View    

def expediente_detalle(request, credencial):
    #Another suggestion is to not abuse CamelCase - look for PEP8
    #It is Python's code-style guide.
    detalle = get_object_or_404(ExpedienteConsultaInicial, credencial_consultainicial=credencial)
    subsequent_consultations = detalle.csb_credencial.all()
    return render(request, 'ExpedienteDetalle.html', {'Expediente_Detalle': detalle, 'consultations': subsequent_consultations})

Useful links:

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

2 different search in a view

分類Dev

Angular: need search bar working on 2 different ng-repeat

分類Dev

Yii 2 gii is generating view files on different directory

分類Dev

Error in search view activity

分類Dev

In android Translate-Animation how to Translate view1 above the another view2, both view exits in different layout

分類Dev

Different Layout in different Table view sections

分類Dev

Django how to create different view

分類Dev

Change scope value in a different view

分類Dev

support Toolbar Versus support search View

分類Dev

Search documents between two dates in a view with a NotesViewNavigator

分類Dev

Find messages by different criteria IMAP.search()

分類Dev

MCTS Search Trees for different start States in a Game

分類Dev

Search two different strings in two columns

分類Dev

Using two different templates for search results - Haystack

分類Dev

Magento Tier Price on Category view is different from Product view

分類Dev

How to redirect on different view on refresh in AngularJS?

分類Dev

Chrome Toggle different devices view destroys the session

分類Dev

How to add different items to a Page View Flutter

分類Dev

Spring Boot 2 Hibernate Search

分類Dev

Navigation bar issue when search is active and push to next view controller

分類Dev

Can a View of multiple tables be used for Full-Text-Search?

分類Dev

Use of full-text search + GIN in a view (Django 1.11 )

分類Dev

How to pass variables to a search view in OpenERP7?

分類Dev

Django : global search in different model - Post result does not appears

分類Dev

How to set different variables for each result of a search in a file?

分類Dev

How can I search multiple lines that contain different values?

分類Dev

vim search - setting different colors for text under cursor

分類Dev

MySQL search different tables and only fetch specfic IDs

分類Dev

Function in excel to search an array of strings for two different sub strings

Related 関連記事

  1. 1

    2 different search in a view

  2. 2

    Angular: need search bar working on 2 different ng-repeat

  3. 3

    Yii 2 gii is generating view files on different directory

  4. 4

    Error in search view activity

  5. 5

    In android Translate-Animation how to Translate view1 above the another view2, both view exits in different layout

  6. 6

    Different Layout in different Table view sections

  7. 7

    Django how to create different view

  8. 8

    Change scope value in a different view

  9. 9

    support Toolbar Versus support search View

  10. 10

    Search documents between two dates in a view with a NotesViewNavigator

  11. 11

    Find messages by different criteria IMAP.search()

  12. 12

    MCTS Search Trees for different start States in a Game

  13. 13

    Search two different strings in two columns

  14. 14

    Using two different templates for search results - Haystack

  15. 15

    Magento Tier Price on Category view is different from Product view

  16. 16

    How to redirect on different view on refresh in AngularJS?

  17. 17

    Chrome Toggle different devices view destroys the session

  18. 18

    How to add different items to a Page View Flutter

  19. 19

    Spring Boot 2 Hibernate Search

  20. 20

    Navigation bar issue when search is active and push to next view controller

  21. 21

    Can a View of multiple tables be used for Full-Text-Search?

  22. 22

    Use of full-text search + GIN in a view (Django 1.11 )

  23. 23

    How to pass variables to a search view in OpenERP7?

  24. 24

    Django : global search in different model - Post result does not appears

  25. 25

    How to set different variables for each result of a search in a file?

  26. 26

    How can I search multiple lines that contain different values?

  27. 27

    vim search - setting different colors for text under cursor

  28. 28

    MySQL search different tables and only fetch specfic IDs

  29. 29

    Function in excel to search an array of strings for two different sub strings

ホットタグ

アーカイブ