Hi all,
i am having trouble to get this query on db table right.
I am always getting error.
Please check shell erorr attached.
I appreciate 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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/ca5a10a1-b8ea-4950-89b7-6806a4682ef8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#models
from __future__ import unicode_literals
from django.db import models, connection
from django.utils import timezone
from datetime import date
class Material(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True, blank=False,
unique=True)
bukrs = models.CharField(db_column='Bukrs', max_length=4)
materialid = models.CharField(db_column='MaterialID', max_length=10)
material_name = models.CharField(db_column='Material_name', max_length=7)
class Meta:
managed = False
db_table = 'Material'
def __str__(self):
return '%s %s %s' % (self.bukrs, self.materialid, self.material_name)
class MaterialGroup(models.Model):
id = models.CharField(db_column='ID', max_length=255, blank=False,
primary_key=True)
material_group = models.CharField(db_column='Material Group',
max_length=255, blank=True, null=True)
class Meta:
managed = False
db_table = 'Material Group'
def __str__(self):
return '%s' % (self.material_group)
class Productgroupinput(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True, blank=False,
unique=True)
bukrs = models.CharField(db_column='Bukrs', max_length=4)
materialid = models.ForeignKey(Material, on_delete=models.CASCADE,
db_column='Materialid', max_length=10)
material_group = models.ForeignKey(MaterialGroup, on_delete=models.CASCADE,
db_column='Material_group', max_length=2)
class Meta:
managed = False
db_table = 'ProductGroupInput'
def __str__(self):
return '%s %s %s' % (self.bukrs, self.materialid, self.material_group)
>>> from productsgrouping.models import Material, MaterialGroup,
>>> Productgroupinput
>>> test = Productgroupinput.objects.all()
>>> test
Traceback (most recent call last):
File
"C:\Users\martici\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\related_des
criptors.py", line 163, in __get__
rel_obj = self.field.get_cached_value(instance)
File
"C:\Users\martici\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\mixins.py",
line 13, in get_cached_value
return instance._state.fields_cache[cache_name]
KeyError: 'materialid'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File
"C:\Users\martici\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\query.py",
line 24
7, in __repr__
return '<%s %r>' % (self.__class__.__name__, data)
File
"C:\Users\martici\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\base.py",
line 503
, in __repr__
return '<%s: %s>' % (self.__class__.__name__, self)
File "C:\Users\martici\QIF\qif\productsgrouping\models.py", line 45, in
__str__
return '%s %s %s' % (self.bukrs, self.materialid, self.material_group)
File
"C:\Users\martici\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\related_des
criptors.py", line 177, in __get__
rel_obj = self.get_object(instance)
File
"C:\Users\martici\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\related_des
criptors.py", line 144, in get_object
return qs.get(self.field.get_reverse_related_filter(instance))
File
"C:\Users\martici\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\query.py",
line 39
9, in get
self.model._meta.object_name
productsgrouping.models.Material.DoesNotExist: Material matching query does not
exist.
>>> query = Material.objects.all()
>>> query
<QuerySet [<Material: 2050 0000100731 Beton>, <Material: 2051 0000100732
Pijesak>, <Material: 2052 0000100332 Mort>, <Ma
terial: 2052 0000100232 Cement>, <Material: 2054 0000100454 Stirop>]>
>>>