Re: import model from other module

2010-07-22 Thread Andreas Pfrengle
David, thanks for the explanation. It suddenly reminds me of the
django tutorials or first chapters I've read probably 3 years ago.
That's surely the right way to do it. I will try that next week.

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



Re: import model from other module

2010-07-21 Thread David De La Harpe Golden
On 20/07/10 20:04, Andreas Pfrengle wrote:
> I've tried it with and without installing in settings.INSTALLED_APPS,
> didn't work, table wasn't created vis syncdb.
> 


> David, nevertheless the link you've posted gave me the clue how to
> solve the problem. I've defined my external module's class as an
> abstract base class:
>  classes>



Well, now I'm worried I led you astray:

Bear in mind that a django "application" can be written to be
_reusable_. (beware django-conventional terminology
here - django says "project" where a lot of people would say "[web]app"
and "app" where some people might say "plugin" or "component")

I don't know what exactly you're doing, but so far I haven't seen stuff
that suggests creating a "django_timer" reusable app and adding it to
the INSTALLED_APPS for any projects you want to use it in isn't what you
really wanted to do, and you've just sorta missed that "app" is a unit
of reusability in django terms.

That's what other responses to you were getting at, but were somewhat
terse (or I'm rather verbose).

So you might make;

django_timer/
__init__.py # empty, probably
models.py
...


with models.py containing a _concrete_ class Tim(models.Model).

Then when you add your "django_timer" to settings.INSTALLED_APPS of a
django project, it will include your Tim model along with other models.


There are large lists of such reusable django "apps" on the web, like
http://djangozen.com/app/


A larger reusable app structure might look like:

django_timer/
__init__.py
admin.py # django admin registration of stuff.
models.py # models you want to be able to use in different projects
views.py  # possibly some associated reusable views.
urls.py # possibly a reusuable url subtree structure.
templates/  # some default/example templates used by views.
django_timer/  # some informal namespace for them
something.html # I prefer .html.djt, but never mind.
templatetags/
django_timer_tags.py # some custom templatetags...
management/
__init__.py
commands/
 __init__.py
 timerfrob.py # custom command "./manage.py timerfrob"


Consider the structure of, say, the django bundled django.contrib apps,
or studying the structure of "pinax", say, might be useful:

http://github.com/pinax/pinax/tree/master/pinax/apps/

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



Re: import model from other module

2010-07-20 Thread Andreas Pfrengle
I've tried it with and without installing in settings.INSTALLED_APPS,
didn't work, table wasn't created vis syncdb.

> This might be the info you're 
> missing:http://docs.djangoproject.com/en/dev/ref/models/options/#app-label
This seems to work, however, since I want to use my external modules
for several projects, I don't want to include code that is specific
for one project (with 'app_label'). I'd need a customized copy for
every project then. Wouldn't be so DRY ;-)

David, nevertheless the link you've posted gave me the clue how to
solve the problem. I've defined my external module's class as an
abstract base class:


Then I only need three lines of code in my project's models.py:
from _external_modules.django_timer import Tim
class Tim(Tim):
pass


Thanks everybody for the help!
Andreas

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



Re: import model from other module

2010-07-20 Thread Andreas Pfrengle
I've tried it with and without installing in settings.INSTALLED_APPS,
didn't work, table wasn't created vis syncdb.

> This might be the info you're 
> missing:http://docs.djangoproject.com/en/dev/ref/models/options/#app-label
This seems to work, however, since I want to use my external modules
for several projects, I don't want to include code that is specific
for one project (with 'app_label'). I'd need a customized copy for
every project then. Wouldn't be so DRY ;-)

David, nevertheless the link you've posted gave me the clue how to
solve the problem. I've defined my external module's class as an
abstract base class:


Then I only need three lines of code in my project's models.py:
from _external_modules.django_timer import Tim
class Tim(Tim):
pass


Thanks everybody for the help!
Andreas

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



Re: import model from other module

2010-07-19 Thread David De La Harpe Golden
On 18/07/10 20:58, Andreas Pfrengle wrote:

> This should import a database-based timer I've written. In fact, code
> from django_timer seems to be imported, since 'test' is printed when I
> execute "manage.py syncdb" - however, the database table is not
> created. Why? What would I need to change to make it work (except copy-
> paste the code into my models.py)?
> 

This might be the info you're missing:
http://docs.djangoproject.com/en/dev/ref/models/options/#app-label

"If a model exists outside of the standard models.py (for instance, if
the app’s models are in submodules of myapp.models), the model must
define which app it is part of"

If your models.py gets very big (one of mine is reaching that point, why
this is fresh in my mind) then there's some chance it's just time to
make several separate django apps, but if you split it up without doing
that, you have to be aware of the above.

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



Re: import model from other module

2010-07-18 Thread Subhranath Chunder
Obviously it can be done. Just make sure to add the app to your
INSTALLED_APPS and use the proper path while importing.
Things should go fine if properly done.

Thanks,
Subhranath Chunder.

On Mon, Jul 19, 2010 at 1:28 AM, Andreas Pfrengle wrote:

> Hello,
>
> is there a possibility to import a model into models.py from any other
> module? In my models.py I'm trying to do:
>
> #models.py:
> from _external_modules.django_timer import Tim
>
> #django_timer.py:
> from django.db import models
> print 'test'
> class Tim(models.Model):
>
>
> This should import a database-based timer I've written. In fact, code
> from django_timer seems to be imported, since 'test' is printed when I
> execute "manage.py syncdb" - however, the database table is not
> created. Why? What would I need to change to make it work (except copy-
> paste the code into my models.py)?
>
> Thanks for answers,
> Andreas
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: import model from other module

2010-07-18 Thread Martin Tiršel
On Sun, 18 Jul 2010 21:58:15 +0200, Andreas Pfrengle  
 wrote:


 when I

execute "manage.py syncdb" - however, the database table is not
created. Why? What would I need to change to make it work (except copy-
paste the code into my models.py)?



Hello,

do you have it in INSTALLED_APPS ?

Regards,
Martin

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



import model from other module

2010-07-18 Thread Andreas Pfrengle
Hello,

is there a possibility to import a model into models.py from any other
module? In my models.py I'm trying to do:

#models.py:
from _external_modules.django_timer import Tim

#django_timer.py:
from django.db import models
print 'test'
class Tim(models.Model):


This should import a database-based timer I've written. In fact, code
from django_timer seems to be imported, since 'test' is printed when I
execute "manage.py syncdb" - however, the database table is not
created. Why? What would I need to change to make it work (except copy-
paste the code into my models.py)?

Thanks for answers,
Andreas

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