Re: ModelAdmin and AlreadyRegistered

2008-03-02 Thread Michael
Ahh sorry. Yea for my projects too, I find it to be the most simple setup.

On Sun, Mar 2, 2008 at 11:32 AM, Rajeev J Sebastian <
[EMAIL PROTECTED]> wrote:

>
> Hello Micheal,
>
> I guess my very terse response caused some misunderstanding.
>
> I meant, we (i.e., dinamis.com in our inhouse projects) put all our
> admin related stuff for each app in an /admin.py and load it at
> startup.
>
> Sorry for the misunderstanding I caused.
>
> Regards
> Rajeev J Sebastian
>
> On Sun, Mar 2, 2008 at 8:43 PM, Michael <[EMAIL PROTECTED]> wrote:
> >
> > On Sun, Mar 2, 2008 at 9:34 AM, Rajeev J Sebastian
> > <[EMAIL PROTECTED]> wrote:
> >
> >
> > >
> > >
> > > On Sun, Mar 2, 2008 at 3:29 AM, Michael Newman <[EMAIL PROTECTED]>
> > wrote:
> > > >
> > > >  To elaborate I just threw 4 lines of code into my contrib.admin
> > > >  __init__:
> > > >  from django.conf import settings
> > > >  for a in settings.INSTALLED_APPS:
> > > > try:
> > > > __import__(a + '.admin')
> > > > except ImportError:
> > > > pass
> > > >  Which will make my life a lot easier. I can't say I have thought
> about
> > > >  every possible problem, but having it so that when someone puts
> > > >  contrib.admin in their installed apps and django automatically
> starts
> > > >  looking for admin.py in installed apps sounds good to me.
> > > We already do this.
> > >
> >
> > Unless I am missing something, I don't see where this is being done. The
> > installed models are run through that right now the system involves
> > importing the admin in that situation. I am still hitting error after
> error
> > in my app that things are already registered due to relationships inside
> my
> > models that I don't see how to avoid.
> >
> >  I think that the second solution that Brian proposed is the best
> solution,
> > but, to me, it sounds strange to accept the fact that a model might be
> > imported twice and ignored the second time. The admin only needs to be
> > imported once, so I don't understand why it should be in an import
> statement
> > in code that might need to be executed several times.
> >
> >  Please guide me where I am wrong,
> >
> >  Thanks, Michael
> >
> >
> >
> >  >
> >
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~--~~~~--~~--~--~---



Re: ModelAdmin and AlreadyRegistered

2008-03-02 Thread Rajeev J Sebastian

Hello Micheal,

I guess my very terse response caused some misunderstanding.

I meant, we (i.e., dinamis.com in our inhouse projects) put all our
admin related stuff for each app in an /admin.py and load it at
startup.

Sorry for the misunderstanding I caused.

Regards
Rajeev J Sebastian

On Sun, Mar 2, 2008 at 8:43 PM, Michael <[EMAIL PROTECTED]> wrote:
>
> On Sun, Mar 2, 2008 at 9:34 AM, Rajeev J Sebastian
> <[EMAIL PROTECTED]> wrote:
>
>
> >
> >
> > On Sun, Mar 2, 2008 at 3:29 AM, Michael Newman <[EMAIL PROTECTED]>
> wrote:
> > >
> > >  To elaborate I just threw 4 lines of code into my contrib.admin
> > >  __init__:
> > >  from django.conf import settings
> > >  for a in settings.INSTALLED_APPS:
> > > try:
> > > __import__(a + '.admin')
> > > except ImportError:
> > > pass
> > >  Which will make my life a lot easier. I can't say I have thought about
> > >  every possible problem, but having it so that when someone puts
> > >  contrib.admin in their installed apps and django automatically starts
> > >  looking for admin.py in installed apps sounds good to me.
> > We already do this.
> >
>
> Unless I am missing something, I don't see where this is being done. The
> installed models are run through that right now the system involves
> importing the admin in that situation. I am still hitting error after error
> in my app that things are already registered due to relationships inside my
> models that I don't see how to avoid.
>
>  I think that the second solution that Brian proposed is the best solution,
> but, to me, it sounds strange to accept the fact that a model might be
> imported twice and ignored the second time. The admin only needs to be
> imported once, so I don't understand why it should be in an import statement
> in code that might need to be executed several times.
>
>  Please guide me where I am wrong,
>
>  Thanks, Michael
>
>
>
>  >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~--~~~~--~~--~--~---



Re: ModelAdmin and AlreadyRegistered

2008-03-02 Thread Michael
On Sun, Mar 2, 2008 at 9:34 AM, Rajeev J Sebastian <
[EMAIL PROTECTED]> wrote:

>
> On Sun, Mar 2, 2008 at 3:29 AM, Michael Newman <[EMAIL PROTECTED]>
> wrote:
> >
> >  To elaborate I just threw 4 lines of code into my contrib.admin
> >  __init__:
> >  from django.conf import settings
> >  for a in settings.INSTALLED_APPS:
> > try:
> > __import__(a + '.admin')
> > except ImportError:
> > pass
> >  Which will make my life a lot easier. I can't say I have thought about
> >  every possible problem, but having it so that when someone puts
> >  contrib.admin in their installed apps and django automatically starts
> >  looking for admin.py in installed apps sounds good to me.
> We already do this.
>

Unless I am missing something, I don't see where this is being done. The
installed models are run through that right now the system involves
importing the admin in that situation. I am still hitting error after error
in my app that things are already registered due to relationships inside my
models that I don't see how to avoid.

I think that the second solution that Brian proposed is the best solution,
but, to me, it sounds strange to accept the fact that a model might be
imported twice and ignored the second time. The admin only needs to be
imported once, so I don't understand why it should be in an import statement
in code that might need to be executed several times.

Please guide me where I am wrong,

Thanks, Michael

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~--~~~~--~~--~--~---



Re: ModelAdmin and AlreadyRegistered

2008-03-02 Thread Rajeev J Sebastian

On Sun, Mar 2, 2008 at 3:29 AM, Michael Newman <[EMAIL PROTECTED]> wrote:
>
>  To elaborate I just threw 4 lines of code into my contrib.admin
>  __init__:
>  from django.conf import settings
>  for a in settings.INSTALLED_APPS:
> try:
> __import__(a + '.admin')
> except ImportError:
> pass
>  Which will make my life a lot easier. I can't say I have thought about
>  every possible problem, but having it so that when someone puts
>  contrib.admin in their installed apps and django automatically starts
>  looking for admin.py in installed apps sounds good to me.
We already do this.

Regards
Rajeev J Sebastian

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~--~~~~--~~--~--~---



Re: ModelAdmin and AlreadyRegistered

2008-03-02 Thread Russell Keith-Magee

On Sat, Mar 1, 2008 at 2:57 AM, Brian Rosner <[EMAIL PROTECTED]> wrote:
>
> I would like to ignite some discussion about removing or changing the
> behavior of AdminSite throwing the AlreadyRegistered exception. More
> and more people are using newforms-admin and I am beginnging to see
> where people are getting tripped up. This maybe simply be a
> documentation problem as there really isn't much on newforms-admin.

I've hit this error a few times myself, but I haven't had a chance to
dig into the code to find the exact cause and the right solution.
However, my preliminary investigations suggested that this was a
variant on the multiple registration problems we used to have before
the model cache was refactored. If this is the case

> Here are a couple options I think we should consider:
>
> 1. Remove the exception and allow subsequent registrations of
> ModelAdmin classes to simply update the registry. This allows for user
> code to override ModelAdmins in django.contrib or other third party
> application. That could also be accomplished with just defining your
> own site, but that path for many beginners may be more difficult unless
> documented well.

This sounds like a recipe for disaster to me. The end result - being
able to extend a ModelAdmin definition - is potentially useful, but
the unpredictability of registration order means that we won't really
be able to easily control (or document) whether ModelAdmin A extends
ModelAdmin B, or vice versa.

> 2. Throw the exception based on whether the ModelAdmin is different
> from a previously registered one. This will technically keep the
> current behavior, but is really special casing the instances where
> admin.site.register is called more than once. This currently happens
> every so often with the models.py which is the documented method of
> registration.

+1 to this option. We need to prevent users from registering a model
with an admin site multiple times, but it is possible for a single
site.register to get invoked multiple times as a result of the import
process. Checking if the registration has changed seems like a good
way to achieve this, and is somewhat analogous to the way the model
cache extracts the app.model name from a model definition and using
that as the basis for eliminating duplicates.

> 3. Keep current behavior and let documentation take care of it.

If I have correctly understood the errors I was getting, this isn't
really something that documentation can (or should) fix, because there
are perfectly valid Python import statements that will cause
difficulty for the admin registration process.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@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-developers?hl=en
-~--~~~~--~~--~--~---