I did not put any max_length restrictions on the IntegerField hence I am not sure what is the issue. The code below is in models.py. Please tell me what else do i need to provide to give a better understanding to this issue.
Django version: Django==3.2
models.py
from django.db import models class Rawdata(models.Model): id = models.IntegerField(db_column='id', primary_key = True) name = models.TextField(blank=True, null=True) node = models.TextField(blank=True, null=True) metal_stack = models.TextField(blank=True, null=True) thickness = models.DecimalField(max_digits=4, decimal_places=2,blank=True, null=True) mstk_id = models.IntegerField(db_column='MStk_id',blank=True, null=True) # Field name made lowercase. restrict = models.TextField(db_column='restrict', blank=True, null=True) # Field name made lowercase. class Meta: db_table = 'rawdata' class Technology(models.Model): id = models.IntegerField(db_column='id', primary_key = True) name = models.CharField(unique=True, max_length=45, blank=True, null=True) node = models.CharField(max_length=45, blank=True, null=True) def __str__(self): return self.name class Meta: db_table = 'technology' unique_together = (('name','node'),) class Metalstack(models.Model): id = models.IntegerField(db_column='id', primary_key = True) techname = models.ForeignKey('Technology', to_field = 'name', on_delete = models.CASCADE, db_column ="techname",blank=True, null=True) stackname = models.CharField(max_length=45, blank=True, null=True, db_column ="stackname") mstk_id = models.IntegerField(blank=True, null=True, db_column ="mstk_id") restrict = models.CharField(max_length=45, blank=True, null=True) def __str__(self): return self.stackname class Meta: db_table = 'metalstack' unique_together = (('techname', 'stackname', 'mstk_id'),) class Thickness(models.Model): id = models.IntegerField(db_column='id', primary_key = True) stack_id = models.ForeignKey(Metalstack, to_field = 'id', on_delete = models.CASCADE, db_column ="stack_id",blank=True, null=True ) thickness = models.DecimalField(max_digits=4, decimal_places=2,blank=True, null=True) class Meta: db_table = 'thickness' unique_together = (('stack_id', 'thickness'),)
admin.py This is the admin.py codes that i ran to sync the different tables in my database that have relationships schema. Everything works fine till i try to access the last table which is the thickness table.
from django.contrib import admin from .models import Technology, Metalstack, Thickness, Rawdata from django.apps import apps class ThickAdmin (admin.ModelAdmin): list_display = ('id','stack_id', 'thickness') fields= ['id','stack_id','thickness'] search_fields = ['stack_id','thickness'] list_filter = [ 'thickness'] prepopulated_fields = {'id':('id',)} ordering = ('id','stack_id') class ModelInLine2(admin.TabularInline): model =Thickness class StackAdmin (admin.ModelAdmin): model = Metalstack list_display = ('id','techname','stackname', 'mstk_dm_id','mstk_restrict') fields= ['id','techname','stackname', 'mstk_dm_id','mstk_restrict'] search_fields = ['stackname'] list_filter = ['techname','mstk_restrict'] prepopulated_fields = {'stackname':('stackname',)} ordering = ('id','stackname') inlines = [ ModelInLine2, ] class ModelInLine(admin.TabularInline): model = Metalstack class TechAdmin (admin.ModelAdmin): model = Technology list_display = ('name','node') search_fields = ['name','node'] list_filter = ['name','node'] prepopulated_fields = {'name':('name',)} ordering = ('id','name') inlines = [ ModelInLine, ]
https://stackoverflow.com/questions/67327665/attributeerror-exception-value-integerfield-object-has-no-attribute-max-leng April 30, 2021 at 11:02AM
没有评论:
发表评论