walkergitonga / django-chronograph

Automatically exported from code.google.com/p/django-chronograph
0 stars 0 forks source link

The model Job is already registered #13

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Download the most recent Chronograph app to your app along with batchadmin.
2. Add them to the settings file
3. Add the following line to the root urls.py file:
url(r'^admin/chronograph/job/(?P<pk>\d+)/run/$', 
'chronograph.views.job_run', name="admin_chronograph_job_run"),
4. Start your app (in this case, development server)
5. Go to the root dir of your app (http://localhost:8000/ in my case)
6. The following error appears:
Caught an exception while rendering: The model Job is already registered

Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in 
get_response
  86.                 response = callback(request, *callback_args, 
**callback_kwargs)
File 
"E:\Dev\Python\mg\trunk\djmastergoal\..\djmastergoal\customtemplatetags\tem
platetags\superbreadcrumbs.py" in wrapped
  177.             return f(*args, **kwargs)
File "E:\Dev\Python\mg\trunk\djmastergoal\..\djmastergoal\views.py" in 
index
  18.     return render_to_response('main/index.html', {'login_form' : 
login_form, 'has_team':has_team,}, 
context_instance=RequestContext(request))
File "C:\Python26\lib\site-packages\django\shortcuts\__init__.py" in 
render_to_response
  18.     return HttpResponse(loader.render_to_string(*args, **kwargs), 
**httpresponse_kwargs)
File "C:\Python26\lib\site-packages\django\template\loader.py" in 
render_to_string
  107.     return t.render(context_instance)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  176.         return self.nodelist.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "C:\Python26\lib\site-packages\django\template\debug.py" in 
render_node
  71.             result = node.render(context)
File "C:\Python26\lib\site-packages\django\template\loader_tags.py" in 
render
  97.         return compiled_parent.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  176.         return self.nodelist.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "C:\Python26\lib\site-packages\django\template\debug.py" in 
render_node
  71.             result = node.render(context)
File "C:\Python26\lib\site-packages\django\template\loader_tags.py" in 
render
  97.         return compiled_parent.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  176.         return self.nodelist.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "C:\Python26\lib\site-packages\django\template\debug.py" in 
render_node
  71.             result = node.render(context)
File "C:\Python26\lib\site-packages\django\template\loader_tags.py" in 
render
  97.         return compiled_parent.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  176.         return self.nodelist.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "C:\Python26\lib\site-packages\django\template\debug.py" in 
render_node
  71.             result = node.render(context)
File "C:\Python26\lib\site-packages\django\template\loader_tags.py" in 
render
  24.         result = self.nodelist.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "C:\Python26\lib\site-packages\django\template\debug.py" in 
render_node
  71.             result = node.render(context)
File "C:\Python26\lib\site-packages\django\template\defaulttags.py" in 
render
  245.                     return self.nodelist_true.render(context)
File "C:\Python26\lib\site-packages\django\template\__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "C:\Python26\lib\site-packages\django\template\debug.py" in 
render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /
Exception Value: Caught an exception while rendering: The model Job is 
already registered

What is the expected output? What do you see instead?
No error page, my normal index page.

What version of the product are you using? On what operating system?
The latest version from the SVN along with Django 1.0.2.

Please provide any additional information below.
When I remove the url line, all seems to go ok, so I thought it had 
something to do with the view, looking at the view's code I saw it included 
the admin module. There seems to be the problem, the admin module is 
running the "admin.site.register" lines at the end twice, one when being 
included by the django admin register and the second one when generating 
the urls.

How did I fix this?
I added an if statement before the two lines at the admin.py module, 
something like this:
if __name__[:12] == "djmastergoal": # djmastergoal is the name of my 
project
    admin.site.register(Job, JobAdmin)
    admin.site.register(Log, LogAdmin)

That seemed to fix it.

Original issue reported on code.google.com by fede.cac...@gmail.com on 19 May 2009 at 12:58

GoogleCodeExporter commented 8 years ago
I had this problem and went for a more portable solution.  I moved JobAdmin 
into a
file called admin_helper.py.  Then I import JobAdmin into admin.py and register 
it,
and then have view.py import JobAdmin from the helper file.  This solves the 
double
registration, without hard-linking the code to your specific project.

Original comment by kyle.dic...@gmail.com on 7 Aug 2009 at 5:24