On 9 syys, 20:06, bmbouter <bmbou...@gmail.com> wrote:
> I have a model defined named OrderOpportunity where I have overridden
> __init__(self).  I have included the relevant parts of the Model below
> as an example.  What I want to understand is why the overridden
> __init__ is being called twice for the creation of a single
> OrderOpportunity DB record.
>
> In models.py:
> class OrderOpportunity(models.Model):
>     def __init__(self):
>         models.Model.__init__(self)
>         print 'foo'
>
> In admin.py:
> class OrderOpportunityAdmin(admin.ModelAdmin):
>     inlines = (ProductForSaleAdmin,)
>
> I enter the admin interface and go to add an OrderOpportunity.  Prior
> to saving the OrderOpportunity instance, I see the following output
> from python manage.py runserver:
>
> Development server is running athttp://127.0.0.1:8080/
> Quit the server with CONTROL-C.
> foo
> foo
> [09/Sep/2010 09:33:50] "GET /admin/bulk_buying_club/orderopportunity/
> add/ HTTP/1.1" 200 9164
> [09/Sep/2010 09:33:50] "GET /admin/jsi18n/ HTTP/1.1" 200 1761
>
> I see foo printed twice which seems strange to me.  Can someone
> provide some insight into two questions I have.  1)  Why is __init__
> being called twice?  2)  Why is jsi18n is also being called when I
> only load the page once?

I can answer the jsi18n part: This is to do with loading translations
for the javascript used in Admin. That is, this is loaded because
there is <script type="text/javascript" src="/admin/jsi18n/..." /> in
the loaded page somewhere.

Why the model is initialized twice? Try: import pdb; pdb.set_trace()
in the __init__ and you will see why that happens.

 - Anssi

-- 
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.

Reply via email to