#3163: [patch] Optionally disable DB table creation from model
------------------------------------------+---------------------------------
Reporter: [EMAIL PROTECTED] | Owner: nobody
Status: reopened | Component: Database
wrapper
Version: SVN | Resolution:
Keywords: | Stage: Design
decision needed
Has_patch: 1 | Needs_docs: 0
Needs_tests: 1 | Needs_better_patch: 0
------------------------------------------+---------------------------------
Comment (by wolfram):
no need to follow the link above, this is the copy/pasted text:
what we did first was implementing just normal models in the models.py,
but that always created the tables in the DB upon "syncdb" (which we
deleted then and created views for). Actually I even wrote a patch for
django where you can mark a model as "create_table=False" but the patch
never made it in.
So we went another actually much better way, after discussing it a lot in
the team. We simply did not create the models in models.py, which are used
for syncdb but we create a file dbviews.py where we put the views' models.
This is very nice separation of code too.
The next step is writing the view itself, which we just did in pure SQL of
course. I.e. if we have the model Forum and we want some specialized
ForumActivity-view then we created a view "CREATE VIEW
core_forumactivityview" (we are on mysql). We then fired that onto our DB
and the model that matched it (make sure to use the same column names as
the view does!!!) simply looks like this:
{{{
class ForumActiviy(models.Model):
all the fields
class Meta:
db_table = "core_forumactivityview"
}}}
now you can simply do
{{{
import project.core.dbviews
}}}
and they just look like models :-).
Depending on how you wrote the view you might even be able to update the
data.
--
Ticket URL: <http://code.djangoproject.com/ticket/3163#comment:15>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---