Since you are new to django and since figuring out how to deal with the legacy database interacting with the django ORM, ignore templates at first.
Focus on writing a function that you can run from `manage.py shell` to extract and display the data, even in just a python dictionary. Then, you can focus on displaying it with templates.
ORM advice:
You need some way to tell which row in the table in your database matches a row in the legacy database. Then you can do something like
oldpatients = dict(oldpatient.useful_id_weirdly_named, oldpatient for oldpatient in LegacyPatients.objects.all())
for patient in Patients.objects.all(): print patient.full_name, oldpatients[patient.useful_id].relevant_info
-- Andrew
(Feedback on my advice appreciated. I hope I don't sound like a tireboot)
On Monday, December 30, 2013, Karthik Kannan wrote:
On Monday, December 30, 2013, Karthik Kannan wrote:
There seems to be no correlation between your User model and your Data model. And also I dont see a field called patientid in any of the forms. Do you mean userid by any chance?--So think about your schema and rebuild your models.The way to display data in Django is through templates. You could write a view the same way you write a query in the python shell to query data and return those values you want using the render function. The use a template to display the data.On Monday, December 30, 2013 11:56:48 PM UTC+5:30, Frank Jaworski wrote:I am new to Django; I have a legacy database I do not control with some information regarding a user and a database on my server with data pertaining to something that user is doing. I want to take some information from each database via the ORM methodology Django employs and display it on a webform, but I am struggling. I search on the patient id and can find what codes they have associated with them, but when it comes to displaying the cost for each code with the associated data, I do not know the best way to do so. Thanks.(my database)class Data(models.Model):code = models.CharField(max_length=12)cost = models.FloatField()unit = models.CharField(max_length=2)(legacy)class UserHistory(models.Model)userid= models.IntegerField(db_column='userid', blank=True, null=True)code = models.CharField(db_column='code', max_length=11, blank=True)firstname = models.CharField(db_column='FirstName', max_length=35, blank=True)middlename = models.CharField(db_column='MiddleName', max_length=35, blank=True)lastname = models.CharField(db_column='LastName', max_length=35, blank=True)Desired Output:Here is the cost for user First Name Last NameLast Name First Name Code Costxxx zzzzz 2 10.00xxx zzzzz 6 10.00xxx zzzzz 7 10.00
xxx zzzzz 11 10.00
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a52f20f6-9d94-44ce-85de-dbe6a3a17cca%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
Pardon brevity; I am on a mobile phone; and quite like haiku
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2By5TLaZGbujMYMhSrUbO2vwhmH3AmodwLpU2GjTYFrn5CBx_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment