Hello,

I struggeling with an error message for more than a day now and I
can't figure out what I'm doing wrong. I'm still kindof a newbie with
python/django so it might be very obvious..

I am trying to create an inline form and I want to hide a field in
this form (specific: I want to hide the pk field, for some reason
django doesn't hide this one when it has a different name than "id").
To achieve this I create a class which inherits admin.StackedInline.
In this class I define formset=modelformset_factory(ClientContact).

When trying to view te form in the admin I get an error, the Traceback
is below.

For testing purposes I made a very simple Client/Client model example,
the code is below.

I really appreciate any tips/suggestions/ideas :)

Greets Jop



model.py
==================================================================
from django.db import models

class Client(models.Model):
    name        = models.CharField(max_length=100)
    city        = models.CharField(max_length=100)

class ClientContact(models.Model):
    contact_id  = models.IntegerField("id", primary_key=True)      #
my database requires this
    title       = models.CharField(max_length=250)
    client      = models.ForeignKey('Client')
==================================================================

admin.py
==================================================================
from testapp.models import *
from django.contrib import admin
from django.forms.models import modelformset_factory

class ClientContactInline(admin.StackedInline):
    model   = ClientContact
    formset = modelformset_factory(ClientContact)  # when I comment
this line out there is no problem

class ClientAdmin(admin.ModelAdmin):
    inlines = [
        ClientContactInline,
    ]

admin.site.register(Client, ClientAdmin)
==================================================================


TRACEBACK
==================================================================
Environment:

Request Method: GET
Request URL: http://testserver/djangocms/admin/testapp/client/1/
Django Version: 1.1.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.redirects',
 'emailtool',
 'contenttool',
 'mainapp',
 'testapp']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  92.                 response = callback(request, *callback_args,
**callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in root
  490.                 return self.model_page(request, *url.split('/',
2))
File "/usr/lib/python2.5/site-packages/django/views/decorators/
cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py"
in model_page
  509.         return admin_obj(request, rest_of_url)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in __call__
  1098.             return self.change_view(request, unquote(url))
File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in
_commit_on_success
  240.                 res = func(*args, **kw)
File "/usr/lib/python2.5/site-packages/django/contrib/admin/
options.py" in change_view
  847.                 formset = FormSet(instance=obj, prefix=prefix)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
__init__
  459.         super(BaseModelFormSet, self).__init__(**defaults)

Exception Type: TypeError at /admin/testapp/client/1/
Exception Value: __init__() got an unexpected keyword argument
'instance'
-- 
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