All right, I think I've got it:

1: I tried to use InlineModelAdmin with a ManyToMany-Field.
You can do this, but you've got to do it as described here I guess:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#working-with-many-to-many-intermediary-models
 
.

2: I confused the model which has the foreign key  with the other one.
If class a has a foreign key to class b, it's class a which inherits  
from TabularInline, not the other way around like I did.

3: You don't have to register Inline classes, as Karen said in her  
mail (which I got while I'm writing this one...Thanks Karen!)

Here's the working example:

from django.db import models

class a(models.Model):
     title = models.CharField(max_length=50)

     def __unicode__(self):
         return self.title

class b(models.Model):
     title = models.CharField(max_length=50)
     other_model = models.ForeignKey('a')

     def __unicode__(self):
         return self.title

admin.py:

from myproject.myapp.models import a, b
from django.contrib import admin

class bInline(admin.TabularInline):
     model = b

class aAdmin(admin.ModelAdmin):
     inlines = [bInline]

admin.site.register(a, aAdmin)

Thanks!
Benjamin


Am 21.01.2009 um 17:36 schrieb Benjamin Buch:

> I simplified the models a bit for better demonstration.
> Here's the model:
>
> from django.db import models
>
> class a(models.Model):
>     title = models.CharField(max_length=50)
>     other_model = models.ManyToManyField('b')
>
>     def __unicode__(self):
>         return self.title
>
> class b(models.Model):
>     title = models.CharField(max_length=50)
>
>     def __unicode__(self):
>         return self.title
>
> Here's admin.py:
>
> from myproject.myapp.models import a, b
> from django.contrib import admin
>
> class bInline(admin.TabularInline):
>     model = b
>
> class aAdmin(admin.ModelAdmin):
>     inlines = [bInline]
>
> admin.site.register(b, bInline)
> admin.site.register(a, aAdmin)
>
> Now, when I'm trying to acess the admin in the browser, I get this  
> error thrown (Traceback):
>
> Traceback:
> File "/Library/Python/2.5/site-packages/django/core/handlers/ 
> base.py" in get_response
>   77.                     request.path_info)
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
> in resolve
>   181.             for pattern in self.url_patterns:
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
> in _get_url_patterns
>   205.         patterns = getattr(self.urlconf_module,  
> "urlpatterns", self.urlconf_module)
> File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py"  
> in _get_urlconf_module
>   200.             self._urlconf_module =  
> __import__(self.urlconf_name, {}, {}, [''])
> File "/Users/benjamin/Code/django/myproject/../myproject/urls.py" in  
> <module>
>   6. admin.autodiscover()
> File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
> __init__.py" in autodiscover
>   54.         __import__("%s.admin" % app)
> File "/Users/benjamin/Code/django/myproject/../myproject/myapp/ 
> admin.py" in <module>
>   10. admin.site.register(b, bInline)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
> sites.py" in register
>   76.             validate(admin_class, model)
> File "/Library/Python/2.5/site-packages/django/contrib/admin/ 
> validation.py" in validate
>   72.     if cls.date_hierarchy:
>
> Exception Type: AttributeError at /admin/
> Exception Value: type object 'bInline' has no attribute  
> 'date_hierarchy'
>
> Thanks,
> Benjamin
>
> Am 21.01.2009 um 17:19 schrieb Karen Tracey:
>
>> On Wed, Jan 21, 2009 at 10:53 AM, Benjamin Buch <[email protected]>  
>> wrote:
>>
>> Hi,
>>
>> I'm trying to use InlineModelAdmins, but get a strange error  
>> thrown...
>>
>> You get this error raised when you do what, exactly?  Also the full  
>> traceback might provide a clue of what is going on.
>>
>> Karen
>
> >


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

Reply via email to