Two django apps (models) using same table

1,547 views
Skip to first unread message

IgorS

unread,
Sep 29, 2011, 1:28:56 PM9/29/11
to Django users
I am new to Django. It might be a very easy question but i could not
google it...

If i have two django apps in the same project and both apps need to
use the same table in the same database, how should i describe this
table in two different models.py files.

Thank you,
-igor

Andre Terra

unread,
Sep 29, 2011, 2:23:27 PM9/29/11
to django...@googlegroups.com
Perhaps https://docs.djangoproject.com/en/dev/ref/models/options/#db-table ?

But you really shouldn't describe the same table twice, if it's exactly the same thing. Move the models.py to a standalone "app" and have your two apps refer to that instead.


Cheers,
AT


--
You received this message because you are subscribed to the Google Groups "Django users" group.
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.


IgorS

unread,
Sep 29, 2011, 5:24:35 PM9/29/11
to Django users
Thank you Andre for your quick answer :-)

I think the second option is a good choice.

From your expertise, does it make sense to follow this approach?
1. Add models.py to the first app added to the project
2. Use [db_table = 'users'] -- without model prefix
3. When new apps are added, refer to the first model

Thank you once again,
-igor

On Sep 29, 2:23 pm, Andre Terra <andrete...@gmail.com> wrote:
> Perhapshttps://docs.djangoproject.com/en/dev/ref/models/options/#db-table?

Konstantinos Pachnis

unread,
Oct 5, 2011, 9:33:11 AM10/5/11
to django...@googlegroups.com
I believe you could also use proxy models in that case. Have a look at https://docs.djangoproject.com/en/1.3/topics/db/models/#proxy-models
Reply all
Reply to author
Forward
0 new messages