- question
i am a beginner of Djanog, i am experiencing a problem of django.core.exceptions.FieldError: Cannot resolve keyword 'ModelList' into field. Choices are: borrows, dept_list, dept_list_id,.....
sometime it shows django.core.exceptions.FieldError: Cannot resolve keyword 'PcStatus_id' into field
-
i have try to remove the files on migrations folder excuted python manage.py makemigrations and migrate ,and reload nginx, restart uwsgi,
-
issue will appear again after the server run normally for a moment. the issue is not heppen immediately after the server up, also ,
-
i have try to rename the field name, but this is not helpful for solving the issue. could you please help chech where is wrong, where does the issue come from ?
'''python
model.py
class pc_list(models.Model):
host_name=models.CharField(max_length=64, unique=True)
service_tag=models.CharField(max_length=45,unique=True)
#hosttype_list=models.ForeignKey('hosttype_list', to_field='id',default=1, on_delete=None)
ModelList=models.ForeignKey('ModelList',to_field='id',on_delete=None)
host_spec=models.CharField(max_length=45)
price=models.FloatField(default=0)
receive_date=models.DateField(auto_now_add =False, default='2018-01-01')
user_list = models.ForeignKey('user_list', to_field='id', on_delete=None, default=180)
seat_no = models.IntegerField(default=14000)
PcStatus=models.ForeignKey('PcStatus', to_field='id', on_delete=None, default=2)
studio = models.CharField(max_length=45, default='-')
site_list=models.ForeignKey('site_list', to_field='id', on_delete=None)
asset_code = models.IntegerField(default=1)
remark=models.TextField(max_length=200, default='-')
mac=models.CharField(max_length=15, default='-')
class Meta:
ordering = ('host_name',)
def __str__(self):
return self.host_name
class PcStatus(models.Model):
statusname=models.CharField(max_length=45,default='--')
def __str__(self):
return self.statusname
class ModelList(models.Model):
name = models.CharField(max_length=40)
hosttype_list = models.ForeignKey('hosttype_list',to_field='id',on_delete=False)
def __str__(self):
return self.name
class Meta:
ordering = ('name',)
**view as below**
class pcDataView(FeedDataView):
token = pc_listTable.token
def get_queryset(self):
siteid = self.request.session.get('current_site')
hosttypeid=self.request.session.get('hosttype_id')
if hosttypeid ==0:
return super(pcDataView, self).get_queryset().filter(site_list_id=siteid , ModelList__hosttype_list_id__in=(1,2,3,12)).exclude(PcStatus_id=4)
else:
return super(pcDataView, self).get_queryset().exclude(PcStatus_id=4).filter(Q(site_list_id=siteid)&Q(ModelList__hosttype_list_id=hosttypeid))
'''
Aucun commentaire:
Enregistrer un commentaire