Re: postgresql views and django

2007-02-22 Thread Marc Fargas Esteve
If the views are already there you can use ./manage.py inspectdb to get
"guessed" models for those views (django will simply treat them as normal
tables), you'll get in trouble if you try to create or update entries of
this model unless you have written INSERT/UPDATE/DELETE rules on the view.

>From django's POV the view is a table, if you have a model that represents
it you're done. There's a "db_table" attribute on the Meta class which you
can use to make the model refer to the view.

The issue comes if the view **is not** there when you run ./manage.py syncdb
as Django will create the table for the model.

You have a few options in this case:
* Create the view before "syncdb"
* Hook on a pre-syncdb signal to create the view or a fake table
* Hook on a post-syncdb signal to drop the (fake)table or create the
view
* There's a ticket on code.djangoproject.com with a patch to get an
optional attribute on Meta "create_table = False" to avoid this issue.

... You should have no trouble to work with views ;)

Hope this Helps!

On 2/22/07, Johannes Wolter <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
>
> I'm new to django and eager to give it a try.
> Now I have a task, where I have data in a postgresql db and i want to
> visualize this data using django. My question now is if it is possible to
> connect the django models with postgresql views which are accessing the
> postgresql tables with the real data.
>
> So my question is
> a) if django really cares if it is operating on views or real tables (I
> only
> need to read the data, no writing)
> b) how complicated it is to create views in postgresql which are fitting
> the
> needs of djangos models
> (c) How about the indices django creates?)
>
> I don't want to get detailed instructions how to do this, just a guess if
> it
> will work and/or if this sounds like a reasonable thing to do.
>
> I tried "django-admin instpectdb", but the problem is, that I don't need
> most
> of the tables in the db, so I get lots of models I don't need and even the
> models I need have many attributes which are useless for the
> visualization.
> But if "inspectdb" is the easier and safer approach, it would be fine too.
>
> I'm glad for any hint!
>
> Cheers,
> Johannes
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



postgresql views and django

2007-02-22 Thread Johannes Wolter

Hi,

I'm new to django and eager to give it a try.
Now I have a task, where I have data in a postgresql db and i want to 
visualize this data using django. My question now is if it is possible to 
connect the django models with postgresql views which are accessing the 
postgresql tables with the real data. 

So my question is
a) if django really cares if it is operating on views or real tables (I only 
need to read the data, no writing)
b) how complicated it is to create views in postgresql which are fitting the 
needs of djangos models
(c) How about the indices django creates?)

I don't want to get detailed instructions how to do this, just a guess if it 
will work and/or if this sounds like a reasonable thing to do.

I tried "django-admin instpectdb", but the problem is, that I don't need most 
of the tables in the db, so I get lots of models I don't need and even the 
models I need have many attributes which are useless for the visualization. 
But if "inspectdb" is the easier and safer approach, it would be fine too.

I'm glad for any hint!

Cheers,
Johannes

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---