Which is the best way of query a database view(no from Django model)

12 views
Skip to first unread message

Andre Lopes

unread,
Nov 3, 2011, 4:04:30 PM11/3/11
to django...@googlegroups.com
Hi,

I'm a new to Django...

I have a database schema that stores me information that I want to
show in a Django website. This database schema have nothing to do with
a Django App...

Which is the best way of doing this in Django? I have read the
documentation and seems to me that I will need to use "custom SQL
directly"(https://docs.djangoproject.com/en/1.3/topics/db/sql/#executing-custom-sql-directly),
right?

If this is correct, where should I put the SQL queries, in "views.py"?


Best Regards,

Daniel Roseman

unread,
Nov 3, 2011, 4:24:28 PM11/3/11
to django...@googlegroups.com
Is there any reason why you can't create models from your existing schema? See https://docs.djangoproject.com/en/1.3/howto/legacy-databases/
--
DR.

Andre Lopes

unread,
Nov 3, 2011, 5:55:31 PM11/3/11
to django...@googlegroups.com
Hi Daniel, thanks for the reply.

I have tested to "inspectdb" but I think the schema is to complex, for
example... for the table "tdir_files_context" (djangoinspectdb.JPG
"image in attachment") I got this model:

[code]
class TdirFilesContext(models.Model):
id_category = models.ForeignKey(TdirCategories, db_column='id_category')
id_file_context = models.CharField(max_length=20)
n_file_context = models.CharField(max_length=150)
coment = models.CharField(max_length=2000)
id_user_db_ins = models.CharField(max_length=45)
id_user_db_upd = models.CharField(max_length=45)
id_user_sys_ins = models.CharField(max_length=45)
id_user_sys_upd = models.CharField(max_length=45)
date_ins = models.DateTimeField()
date_last_upd = models.DateTimeField()
class Meta:
db_table = u'tdir_files_context'
[/code]

This database table have Two primary keys and One foreign key. The
Django Model handle this kind of database tables?


Best Regards,

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/khJaBBbvxfIJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

djangoinspectdb.JPG
Reply all
Reply to author
Forward
0 new messages