Data entry form with Django

0

Someone can help me, I have the following model:

class Citas2(models.Model):
    laboratorio = models.CharField(max_length=10, default=LABORATORIO_1, null=True)
    paciente = models.ForeignKey(Pacientes, on_delete=models.CASCADE)
    doctor = models.ForeignKey(Doctores, on_delete=models.CASCADE)
    examen = models.ForeignKey(Examenes, on_delete=models.CASCADE)

class Examenes(models.Model):
    descripcion = models.CharField(max_length=100)
    precio = models.IntegerField()
    codigo = models.CharField(max_length=50)

This form that I entered the exams:

class ExamenesForm(forms.ModelForm):
    class Meta:
        model = Examenes
        fields = '__all__'
        widgets = {
            'descripcion': forms.TextInput(attrs={'class': 'form-control'}),
            'codigo': forms.TextInput(attrs={'class': 'form-control'}),
            'precio': forms.TextInput(attrs={'class': 'form-control'}),
        }

View to enter exams

class ExamenesCreate(CreateView):
    model = Examenes()
    form_class = ExamenesForm
    template_name = 'examenes.html'

    def get_success_url(self):
        return reverse('laboratorio:consultar_examenes')

Form to try to enter the Appointments

class OrdenForm(forms.ModelForm):
    class Meta:
        model = Citas2
        fields = '__all__'
        widgets = {
           'paciente': forms.TextInput(attrs={'class': 'form-control'}),
           'doctor': forms.TextInput(attrs={'class': 'form-control'}),          
           'examen': forms.TextInput(attrs={'class': 'form-control'}),          
           'laboratorio': forms.TextInput(attrs={'class': 'form-control'}),

        }

What I want is to enter several exams per patient, that is, a patient can have many exams, that would be the relationship. that is, in the table Appointments2:

It is complicated in the Exams section because I have to add several per patient and I do not enter them but I look for them already added.  I would appreciate someone to give me a guideline ...

    
asked by Roberto Feijoo 12.07.2018 в 19:20
source

0 answers