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=80, blank=True, null=True)
# Field name made lowercase.
family = models.ForeignKey(
'Family', on_delete=models.CASCADE, db_column='familyid', blank=True, null=True)
# Field name made lowercase.
isdeceased = models.BooleanField(
db_column='isdeceased', blank=True, null=True)
deceased_date = models.DateField(blank=True, null=True)
# Field name made lowercase.
phone = models.CharField(
db_column='phone', max_length=50, blank=True, null=True)
email = models.EmailField(blank=True, null=True)
# Field name made lowercase.
gender = models.CharField(
db_column='gender', max_length=1, choices=gender_CHOICES, blank=True, null=True)
# Field name made lowercase.
fullname = models.CharField(
db_column='fullname', max_length=255, blank=True, null=True)
alias = models.CharField(
db_column='alias', max_length=50, blank=True, null=True)
birth_date = models.DateField(blank=True, null=True)
health_issues = models.TextField(
db_column='health_issues', blank=True, null=True)
isscout = models.BooleanField(
db_column='isscout', blank=True, null=True)
isparent = models.BooleanField(
db_column='isparent', blank=True, null=True)
isleader = models.BooleanField(
db_column='isleader', blank=True, null=True)
fatherid = models.ForeignKey(
'self', blank=True, null=True, related_name='father', on_delete=models.CASCADE)
motherid = models.ForeignKey(
'self', blank=True, null=True, related_name='mother', on_delete=models.CASCADE)
spouseid = models.ForeignKey(
'self', blank=True, null=True, related_name='spouse', on_delete=models.CASCADE)
date_married = models.DateField(blank=True, null=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=80, blank=True, null=True)
# Field name made lowercase.
family = models.ForeignKey(
'Family', on_delete=models.CASCADE, db_column='familyid', blank=True, null=True)
# Field name made lowercase.
isdeceased = models.BooleanField(
db_column='isdeceased', blank=True, null=True)
deceased_date = models.DateField(blank=True, null=True)
# Field name made lowercase.
phone = models.CharField(
db_column='phone', max_length=50, blank=True, null=True)
email = models.EmailField(blank=True, null=True)
# Field name made lowercase.
gender = models.CharField(
db_column='gender', max_length=1, choices=gender_CHOICES, blank=True, null=True)
# Field name made lowercase.
fullname = models.CharField(
db_column='fullname', max_length=255, blank=True, null=True)
alias = models.CharField(
db_column='alias', max_length=50, blank=True, null=True)
birth_date = models.DateField(blank=True, null=True)
health_issues = models.TextField(
db_column='health_issues', blank=True, null=True)
isscout = models.BooleanField(
db_column='isscout', blank=True, null=True)
isparent = models.BooleanField(
db_column='isparent', blank=True, null=True)
isleader = models.BooleanField(
db_column='isleader', blank=True, null=True)
fatherid = models.ForeignKey(
'self', blank=True, null=True, related_name='father', on_delete=models.CASCADE)
motherid = models.ForeignKey(
'self', blank=True, null=True, related_name='mother', on_delete=models.CASCADE)
spouseid = models.ForeignKey(
'self', blank=True, null=True, related_name='spouse', on_delete=models.CASCADE)
date_married = models.DateField(blank=True, null=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=True, related_name='scoutcontact') # Field name made lowercase.
current_class = models.ForeignKey(
OvClass, on_delete=models.CASCADE, blank=True, null=True)
current_grade = models.IntegerField(null=True, blank=True)
g1_id = models.ForeignKey(
'self', on_delete=models.CASCADE, blank=True, null=True, related_name='g1')
g2_id = models.ForeignKey(
'self', on_delete=models.CASCADE, blank=True, null=True, related_name='g2')
hobbies = models.TextField(
db_column='hobbies', blank=True, null=True)
skills = models.TextField(
db_column='skills', blank=True, null=True)
reason = models.TextField(
db_column='reason', blank=True, null=True)
date_joined = models.DateField(blank=True, null=True)
grade_joined = models.IntegerField(blank=True, null=True)
start_academic_year = models.IntegerField(blank=True, null=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(self, record):
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..."
On Wed, Mar 25, 2020 at 2:12 PM Motaz Hejaze <trapperx.1@gmail.com> wrote:
it will be much easier if you share your models and the error--On Wed, Mar 25, 2020 at 8:06 PM Nader Elsisi <naderelsisi@gmail.com> wrote: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
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+unsubscribe@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.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHV4E-fXbM3ET6oQyX66pe6n%2B%3DPN_8koPTzhOYb-1EFoi9MRtQ%40mail.gmail.com.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BkREvpCWf0JFy981tgqKPHpFd9nJpxD2U9N8pF70nn8YE2K%2Bg%40mail.gmail.com.
No comments:
Post a Comment