model inheritance

25 views
Skip to first unread message

Roberto López López

unread,
Oct 2, 2013, 12:46:21 PM10/2/13
to django...@googlegroups.com
Hi,

I am extending a 3rd party model in my application, using multi-table inheritance. I can create an instance and modify it, but when I try to list the created objects at http://localhost:8000/en/admin/news/news/ , I am getting a nice exception:

Traceback:
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  140.                     response = response.render()
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/response.py" in render
  105.             self.content = self.rendered_content
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content
  82.         content = template.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  124.         return compiled_parent._render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  124.         return compiled_parent._render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  63.             result = block.nodelist.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  63.             result = block.nodelist.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py" in render
  1185.                     _dict = func(*resolved_args, **resolved_kwargs)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in result_list
  286.             'results': list(results(cl))}
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in results
  264.             yield ResultList(None, items_for_result(cl, res, None))
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in __init__
  256.         super(ResultList, self).__init__(*items)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in items_for_result
  219.             url = cl.url_for_result(result)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/contrib/admin/views/main.py" in url_for_result
  380.         pk = getattr(result, self.pk_attname)

Exception Type: AttributeError at /en/admin/news/news/
Exception Value: 'News' object has no attribute 'news_ptr_id'
My News model is extending another model using multiple table inheritance.
class News(OldNews):
    departments = models.ManyToManyField(Department, blank=True, related_name='news')
    objects = models.Manager()
    class Meta:
        verbose_name_plural = _('news')
        ordering = ('-pub_date', )

I can't understand the reason for this error. Can anyone enlighten me please?
Roberto

Leonardo Giordani

unread,
Oct 2, 2013, 1:45:42 PM10/2/13
to django...@googlegroups.com
Are you sure your DB has been synced after putting the ForeignKey(News) in your Department model?
Can you post somewhere the following models: News, OldNews, Department?

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat
My profile on About.me - My GitHub page - My Coderwall profile


2013/10/2 Roberto López López <robert...@uni.no>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/524C159D.8020201%40uni.no.
For more options, visit https://groups.google.com/groups/opt_out.

Roberto López López

unread,
Oct 2, 2013, 2:04:15 PM10/2/13
to django...@googlegroups.com

Hi Leonardo, thanks for your answer.

Yes, it has been synced.

The model itself is a little bit bigger, as you can notice from the code https://dpaste.de/c3Rg I am using as well the News model from https://github.com/wildfish/cmsplugin_news/blob/master/cmsplugin_news/models.py

Regards,

Roberto

For more options, visit https://groups.google.com/groups/opt_out.


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

Roberto López López

unread,
Oct 2, 2013, 2:35:28 PM10/2/13
to django...@googlegroups.com

Is there maybe a way to set the cmsplugin_news.News.Meta.abstract option to True? In order to prevent accessing the parent model to fetch the inherited data.




On 10/02/2013 03:45 PM, Leonardo Giordani wrote:

For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages