Thursday, September 9, 2010

Overridden Model __init__ being called twice

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 at http://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?

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

No comments:

Post a Comment