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 622771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:01:14+00:00 2026-05-13T19:01:14+00:00

good day guys! in project, among others, have models: class Category(models.Model): name = models.CharField(max_length

  • 0

good day guys!
in project, among others, have models:

class Category(models.Model):

    name = models.CharField(max_length = 50, blank = False, null = False)

    def __unicode__(self):
        return "Category %s" % self.name

    class Meta:
        db_table = "categories"
        managed = False


class Site(models.Model):

    user = models.ForeignKey(User, blank = False, null = False, db_column = "user_id")
    name = models.URLField(verify_exists = True, blank = False, null = False)
    categories = models.ManyToManyField(Category, blank = True, through = "CategorySites", verbose_name = "Category")

    def __unicode__(self):
        return self.name

    class Meta:
        db_table = "sites"
        managed = False



class CategorySites(models.Model):

    site = models.ForeignKey(Site, blank = False, null = False, db_column = "site_id")
    category = models.ForeignKey(Category, blank = False, null = False, db_column = "category_id")

    def __unicode__(self):
        return "Relation between site %s and category %s" % (self.site.name, self.category.name)

    class Meta:
        db_table = "categories_sites"
        managed = False

so, as you see there is many-to-many relation. generally it work well – i can add and manage models through manage.py shell, or server-side functions.
I want to enable editing this type of relation on admin site, so, i’ve added admin model for Sites:

 class SiteAdmin(admin.ModelAdmin):

    list_display = ('id', 'name')
    list_filter = ('name', 'categories')

    fieldsets = (
        (None, {"fields": ("categories",)}),
    )

    def queryset(self, request):
        qs = super(SiteAdmin, self).queryset(request)
        if request.user.is_superuser:
            return qs
        else:
            return qs.filter(user = request.user)

    def has_change_permission(self, request, obj=None):
        if not obj:
            return True # So they can see the change list page
        if request.user.is_superuser or obj.user == request.user:
            return True
        else:
            return False

    has_delete_permission = has_change_permission

but when i’m going in admin->sites->Add site (or edit) django throws Caught an exception while rendering: ‘NoneType’ object has no attribute ‘label’ .
how can if fix it?

  • 1 1 Answer
  • 1 View
  • 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-05-13T19:01:14+00:00Added an answer on May 13, 2026 at 7:01 pm

    For that you need to add undocumented formfield_for_manytomany method to your SiteAdmin class:

    from django.contrib.admin import widgets
    
    class SitebAdmin(admin.ModelAdmin):
    
       list_display = ('id', 'name')
       list_filter = ('name', 'categories')
    
       def formfield_for_manytomany(self, db_field, request, **kwargs):
          if db_field.name == 'categories':
             kwargs['widget'] = widgets.FilteredSelectMultiple(
                  db_field.verbose_name, (db_field.name in self.filter_vertical))
          return super(SitebAdmin, self).formfield_for_foreignkey(
             db_field, request, **kwargs)
    
       fieldsets = (
           (None, {
                "fields": ("name", "categories",)
           }),
       )
    

    to override default of not displaying multiple select widget for models with through option specified docs.

    Although this works I still think that this should not cause error in Django.

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

Sidebar

Related Questions

Good day, I have a hibernate mapping which goes something like this <class name=Person>
Good day guys. I have the following struct and class, template <class T> struct
Good day, I have the following problem: class B extends class A and methods
Good day guys, I've got quite a specific data model that I'm trying to
Good day guys, I would like to inquire if anyone of you may have
Good day to you guys I have an application that has a UITabBarController for
Good day. I have little usage of Flash CS4, however i have to build
Good day, If I have for example the documents which have the following fields
Good day, I have a gen_server process which does some long-running state-updating tasks periodically
Good day, to stackoverflow community. I have run into a bug with regard to

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.