I want to apply “Consults and Hospitalization” to each/specific Patient. How can I do that?
I use CreateView/UpdateView(…) to manage patients profiles, where I want to print into a table the Consults for each Patient(where i can access them to Edit/Delete…).
Views.py for Patient profile, where I access the form for adding a Hospitalization:
class PatientUpdateView(LoginRequiredMixin, UpdateView):
model = Patient
template_name = 'Manage/PageAddHos.html'
form_class = forms.FormAddHost# I create in Forms.py a form, using form|crispy
def form_valid(self, form):
form.instance.autor = self.request.user
messages.success(self.request, f"...")
return super().form_valid(form)
The problem: I want to access my Add_Consult form(which I access from Patient"DetailView"), where Name, Personal_ID, Gender(…) to autocomplete for that Patient.
Thank you for your time!
I’m trying to decode your question. Here is what I got:
You want to automatically enter values into the Consult and Hospitalization models after creating/updating the Patient?
Not realy.
I want to add consultations & hospitalizations, and these must be assigned per patient.
Now I get this error: DETAIL: Failing row contains (6, 2022-06-18 09: 50: 32.722841 + 00, 2022-06-18 00: 00: 00 + 00, NE, something, something, null).
I know that in the last field, “null” must be the patient’s id, but I don’t know how to get it. #this is my view for add a Consult, but when I submit the form, I got that error:
In this general case, your link from the Patient page to this Consult page needs to pass the Patient id as a url parameter, which you can then assign as the patient_id field of the Consult model when being created.
Side note: I suggest you adopt the standard Python and Django code conventions - it’s going to help you a lot in the long run. Specifically in this case, class names such as Consult are properly capitalized. However, the names of the fields (symptoms and patient should not be.) Likewise, you want to be consistent with your naming patterns. You use the “word_word” style for hospitalization_section (good), but then you have “NameandLastName” instead of either name_and_last_name (if that’s what you want) or possibly full_name.
This is going into which table/model? Its hard to know exactly what you are trying to do when relevant parts of your code are missing. Otherwise, can you share the line preceeding that error message?