no default manager for tables2 object

16 views
Skip to first unread message

Nader Elsisi

unread,
Mar 25, 2020, 2:07:56 PM3/25/20
to django...@googlegroups.com
I have a tables2 table. And I got this error. I searched the net and followed a lot 
But couldn't fix it.

The tables2 object is for a inherited model and linked through onetoone foreign key.

The main object table2 is working fine. But this inherited model has more attributes and fewer objects than the main object.


I checked the naming of fields.
Tried to setup the default manager.

Thanks for your help

Motaz Hejaze

unread,
Mar 25, 2020, 2:12:52 PM3/25/20
to django...@googlegroups.com
it will be much easier if you share your models and the error

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BkREvpv1g-7JzCYNSzjvVXJ7cQwt14pMuimf_NSuspEABucXQ%40mail.gmail.com.

Nader Elsisi

unread,
Mar 25, 2020, 4:21:15 PM3/25/20
to django...@googlegroups.com
models.py
class Contact(models.Model):
    gender_CHOICES = (
        ('M''Male'),
        ('F''Female'),
    )

    # Field name made lowercase.
    id = models.IntegerField(db_column='id'primary_key=True)
    # Field name made lowercase.
    name = models.CharField(
        db_column='name'max_length=80blank=Truenull=True)
    # Field name made lowercase.
    family = models.ForeignKey(
        'Family'on_delete=models.CASCADE, db_column='familyid'blank=Truenull=True)
    # Field name made lowercase.
    isdeceased = models.BooleanField(
        db_column='isdeceased'blank=Truenull=True)
    deceased_date = models.DateField(blank=Truenull=True)
    # Field name made lowercase.
    phone = models.CharField(
        db_column='phone'max_length=50blank=Truenull=True)
    email = models.EmailField(blank=Truenull=True)
    # Field name made lowercase.
    gender = models.CharField(
        db_column='gender'max_length=1choices=gender_CHOICES, blank=Truenull=True)

    # Field name made lowercase.
    fullname = models.CharField(
        db_column='fullname'max_length=255blank=Truenull=True)
    alias = models.CharField(
        db_column='alias'max_length=50blank=Truenull=True)

    birth_date = models.DateField(blank=Truenull=True)
    health_issues = models.TextField(
        db_column='health_issues',  blank=Truenull=True)

    isscout = models.BooleanField(
        db_column='isscout'blank=Truenull=True)

    isparent = models.BooleanField(
        db_column='isparent'blank=Truenull=True)

    isleader = models.BooleanField(
        db_column='isleader'blank=Truenull=True)

    fatherid = models.ForeignKey(
        'self'blank=Truenull=Truerelated_name='father'on_delete=models.CASCADE)
    motherid = models.ForeignKey(
        'self'blank=Truenull=Truerelated_name='mother'on_delete=models.CASCADE)
    spouseid = models.ForeignKey(
        'self'blank=Truenull=Truerelated_name='spouse'on_delete=models.CASCADE)
    date_married = models.DateField(blank=Truenull=True)
    # Field name made lowercase.
    # title = models.CharField(
    #     db_column='title', max_length=50, blank=True, null=True)

    def __str__(self):
        return self.name

    class Meta:
        managed = True
        db_table = 'contacts'
        ordering = ['name']
class Contact(models.Model):
    gender_CHOICES = (
        ('M''Male'),
        ('F''Female'),
    )

    # Field name made lowercase.
    id = models.IntegerField(db_column='id'primary_key=True)
    # Field name made lowercase.
    name = models.CharField(
        db_column='name'max_length=80blank=Truenull=True)
    # Field name made lowercase.
    family = models.ForeignKey(
        'Family'on_delete=models.CASCADE, db_column='familyid'blank=Truenull=True)
    # Field name made lowercase.
    isdeceased = models.BooleanField(
        db_column='isdeceased'blank=Truenull=True)
    deceased_date = models.DateField(blank=Truenull=True)
    # Field name made lowercase.
    phone = models.CharField(
        db_column='phone'max_length=50blank=Truenull=True)
    email = models.EmailField(blank=Truenull=True)
    # Field name made lowercase.
    gender = models.CharField(
        db_column='gender'max_length=1choices=gender_CHOICES, blank=Truenull=True)

    # Field name made lowercase.
    fullname = models.CharField(
        db_column='fullname'max_length=255blank=Truenull=True)
    alias = models.CharField(
        db_column='alias'max_length=50blank=Truenull=True)

    birth_date = models.DateField(blank=Truenull=True)
    health_issues = models.TextField(
        db_column='health_issues',  blank=Truenull=True)

    isscout = models.BooleanField(
        db_column='isscout'blank=Truenull=True)

    isparent = models.BooleanField(
        db_column='isparent'blank=Truenull=True)

    isleader = models.BooleanField(
        db_column='isleader'blank=Truenull=True)

    fatherid = models.ForeignKey(
        'self'blank=Truenull=Truerelated_name='father'on_delete=models.CASCADE)
    motherid = models.ForeignKey(
        'self'blank=Truenull=Truerelated_name='mother'on_delete=models.CASCADE)
    spouseid = models.ForeignKey(
        'self'blank=Truenull=Truerelated_name='spouse'on_delete=models.CASCADE)
    date_married = models.DateField(blank=Truenull=True)
    

    def __str__(self):
        return self.name

    class Meta:
        managed = True
        db_table = 'contacts'
        ordering = ['name']


class Scout(Contact):
    objects = models.Manager()

    contact = models.OneToOneField('Contact'on_delete=models.CASCADE, db_column='contact_id',
                                   parent_link=Truerelated_name='scoutcontact')  # Field name made lowercase.
    current_class = models.ForeignKey(
        OvClass, on_delete=models.CASCADE, blank=Truenull=True)
    current_grade = models.IntegerField(null=Trueblank=True)
    g1_id = models.ForeignKey(
        'self'on_delete=models.CASCADE, blank=Truenull=Truerelated_name='g1')
    g2_id = models.ForeignKey(
        'self'on_delete=models.CASCADE, blank=Truenull=Truerelated_name='g2')
    hobbies = models.TextField(
        db_column='hobbies',  blank=Truenull=True)
    skills = models.TextField(
        db_column='skills',  blank=Truenull=True)
    reason = models.TextField(
        db_column='reason',  blank=Truenull=True)
    date_joined = models.DateField(blank=Truenull=True)
    grade_joined = models.IntegerField(blank=Truenull=True)
    start_academic_year = models.IntegerField(blank=Truenull=True)

   

    class Meta:
        managed = True
        db_table = 'scout'
        default_manager_name = 'objects'
        # ordering = ['name']




tables.py
class ScoutTable(tables.Table):
    objects = models.Manager()

    select_chkbox = tables.CheckBoxColumn(accessor="pk"attrs={"th__input": {"onclick""toggle(this)"}, "td__input": {"onclick""countbox(this)"}},
                                          orderable=False)

    SN = tables.Column(empty_values=(), orderable=False)
    name = tables.LinkColumn('update-scout'args=[A('pk')])
    # name = tables.LinkColumn('update-contact', args=[A('pk')])
    # delete = tables.TemplateColumn(TEMPLATE, orderable=False)
    delete = tables.LinkColumn('delete_item'args=[A('pk')], attrs={
        'a': {'class''btn btn-small btn-dark'}
    })

    
    def __init__(self, *args, **kwargs):
        super(ScoutTable, self).__init__(*args, **kwargs)
        self.counter = itertools.count(1)
        # self.cells = CellAccessor(self)

    

    #

    def render_SN(selfrecord):

        pg = getattr(self'paginator'None)
        if pg:
            v = next(self.counter)
            # 'Row %d' % next(self.counter)
            return v + self.paginator.per_page * (self.page.number-1)
        else:
            return next(self.counter)
        

    class Meta:

        model = Scout
        default_manager_name = 'objects'
        
        fields = ('select_chkbox''SN''id''name''family',
                  'phone''email',
                  )

        
        # managed = True
        attrs = {"class""table-striped table-bordered"'width''100%'}
        empty_text = "There are no Contact matching the search criteria..."


Nader Elsisi

unread,
Mar 25, 2020, 4:24:05 PM3/25/20
to django...@googlegroups.com

AttributeError at /scoutstablefilter/

type object 'ScoutTable' has no attribute '_default_manager'
Request Method:GET
Request URL:http://localhost:8000/scoutstablefilter/
Django Version:3.0.3
Exception Type:AttributeError
Exception Value:
type object 'ScoutTable' has no attribute '_default_manager'
Exception Location:C:\Users\nader\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\views\generic\list.py in get_queryset, line 33
Python Executable:C:\Users\nader\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version:3.8.1
Python Path:
['C:\\Dev\\python\\scouts',
 'C:\\Users\\nader\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
 'C:\\Users\\nader\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
 'C:\\Users\\nader\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
 'C:\\Users\\nader\\AppData\\Local\\Programs\\Python\\Python38-32',
 'C:\\Users\\nader\\AppData\\Roaming\\Python\\Python38\\site-packages',
 'C:\\Users\\nader\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
Server time:Wed, 25 Mar 2020 17:59:25 +0000

Traceback Switch to copy-and-paste view

  • C:\Users\nader\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\exception.py in inner
    1.             response = get_response(request)
  • C:\Users\nader\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py in _get_response
    1.                 response = self.process_exception_by_middleware(e, request)
  • C:\Users\nader\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py in _get_response
    1.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  • C:\Users\nader\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\views\generic\base.py in view
    1.             return self.dispatch(request, *args, **kwargs)
  • C:\Users\nader\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\views\generic\base.py in dispatch
    1.         return handler(request, *args, **kwargs)
Reply all
Reply to author
Forward
0 new messages