Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:26:31+00:00 2026-06-04T00:26:31+00:00

I’m trying to build an admin panel where users can populate the database with

  • 0

I’m trying to build an admin panel where users can populate the database with some rules; every user can see and edit, for certain entity/models, only own data.

for do this I’m inheriting a modelAdmin class in this way

#my models

class Product(models.Model):
    name = models.CharField(max_length=80)
    description = models.TextField()
    author = models.ForeignKey(User)

    def __unicode__(self):
        return self.name

class Variant(models.Model):
    size = models.DecimalField(max_digits=3, decimal_places=0)
    author = models.ForeignKey(User)
    super_product = models.ForeignKey(Product)

    def __unicode__(self):
        return "%s %s" % (self.size)

#in urls.py

class FilterProduct(admin.ModelAdmin):
    def queryset(self, request):
        qs = super(FilterProduct, self).queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(author=request.user)

    def save_model(self, request, obj, form, change):
        if not request.user.is_superuser:
            obj.author = request.user

        obj.save()

class FilterVariant(admin.ModelAdmin):
    def queryset(self, request):
        qs = super(FilterVariant, self).queryset(request)
        if request.user.is_superuser:
            return qs
        return qs.filter(author=request.user)

    def save_model(self, request, obj, form, change):
        if not request.user.is_superuser:
            obj.author = request.user

        obj.save()

    def get_form(self, request, obj, **kwargs):
        form = super(FilerVariant,self).get_form(self,request, obj,**kwargs)

        if not request.user.is_superuser:
            form.base_fields['super_product'].queryset = form.base_fields['super_product'].queryset.filter(author=request.user)

        return form

admin.site.register(Product,FilterProduct)
admin.site.register(Variant,FilterVariant)

when I’m trying to add a Variant I get this error

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/prodotti/varianti/add/
Django Version: 1.2.3
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'prodotti',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in wrapper
  265.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in _wrapped_view
  76.                     response = view_func(request, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/views/decorators/cache.py" in _wrapped_view_func
  69.         response = view_func(request, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/contrib/admin/sites.py" in inner
  190.             return view(request, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in _wrapper
  21.             return decorator(bound_func)(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in _wrapped_view
  76.                     response = view_func(request, *args, **kwargs)
File "/usr/lib/pymodules/python2.6/django/utils/decorators.py" in bound_func
  17.                 return func(self, *args2, **kwargs2)
File "/usr/lib/pymodules/python2.6/django/db/transaction.py" in _commit_on_success
  299.                     res = func(*args, **kw)
File "/usr/lib/pymodules/python2.6/django/contrib/admin/options.py" in add_view
  799.         ModelForm = self.get_form(request)

Exception Type: TypeError at /admin/prodotti/varianti/add/
Exception Value: get_form() takes exactly 3 arguments (2 given)

maybe is a stupid problem, where is the mistake? Am I giving to the function all the needing parameters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:26:33+00:00Added an answer on June 4, 2026 at 12:26 am

    There are a couple of errors here.

    Firstly, the original signature of the get_form method is def get_form(self, request, obj=None, **kwargs) – that is, the obj argument is optional (which makes sense, as when you’re creating a new item, there is no existing object). However, you’ve overridden it with this: def get_form(self, request, obj, **kwargs) – ie now the obj argument is required.

    Unless you have complete control over how your method is going to be called – which you don’t in this case, because it’s done by the admin – you should ensure that your method can accept the same arguments as the original, at the very least.

    Your second error is in the next line:

    form = super(FilerVariant,self).get_form(self,request, obj,**kwargs)
    

    Here you’ve duplicated the self argument – you mustn’t pass it explicitly in the method call, as it’s already passed as the first argument.

    Finally, you should definitely think about upgrading – Django 1.2 was released two years ago, there’s been a lot of changes since then.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.