Add correct use of db_model field to Attributes.

This commit is contained in:
Griatch 2017-01-22 17:22:52 +01:00
parent 982b11ddfb
commit b6c2aaedc5
2 changed files with 16 additions and 4 deletions

View file

@ -11,7 +11,6 @@ which is a non-db version of Attributes.
from builtins import object from builtins import object
import re import re
import weakref import weakref
from collections import defaultdict
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
@ -279,6 +278,7 @@ class AttributeHandler(object):
else: else:
# we have to query to make this category up-date in the cache # we have to query to make this category up-date in the cache
query = {"%s__id" % self._model : self._objid, query = {"%s__id" % self._model : self._objid,
"attribute__db_model" : self._model,
"attribute__db_attrtype" : self._attrtype, "attribute__db_attrtype" : self._attrtype,
"attribute__db_category__iexact" : category.lower() if category else None} "attribute__db_category__iexact" : category.lower() if category else None}
attrs = [conn.attribute for conn in getattr(self.obj, attrs = [conn.attribute for conn in getattr(self.obj,
@ -478,8 +478,10 @@ class AttributeHandler(object):
attr_obj.value = value attr_obj.value = value
else: else:
# create a new Attribute (no OOB handlers can be notified) # create a new Attribute (no OOB handlers can be notified)
kwargs = {"db_key" : keystr, "db_category" : category, kwargs = {"db_key" : keystr,
"db_model" : self._model, "db_attrtype" : self._attrtype, "db_category" : category,
"db_model" : self._model,
"db_attrtype" : self._attrtype,
"db_value" : None if strattr else to_pickle(value), "db_value" : None if strattr else to_pickle(value),
"db_strvalue" : value if strattr else None} "db_strvalue" : value if strattr else None}
new_attr = Attribute(**kwargs) new_attr = Attribute(**kwargs)
@ -546,7 +548,9 @@ class AttributeHandler(object):
attr_obj.value = new_value attr_obj.value = new_value
else: else:
# create a new Attribute (no OOB handlers can be notified) # create a new Attribute (no OOB handlers can be notified)
kwargs = {"db_key" : keystr, "db_category" : category, kwargs = {"db_key" : keystr,
"db_category" : category,
"db_model": self._model,
"db_attrtype" : self._attrtype, "db_attrtype" : self._attrtype,
"db_value" : None if strattr else to_pickle(new_value), "db_value" : None if strattr else to_pickle(new_value),
"db_strvalue" : value if strattr else None} "db_strvalue" : value if strattr else None}

View file

@ -7,6 +7,14 @@ from django.db import migrations
def update_tags_with_dbmodel(apps, schema_editor): def update_tags_with_dbmodel(apps, schema_editor):
Tag = apps.get_model('typeclasses', 'Tag') Tag = apps.get_model('typeclasses', 'Tag')
Attribute = apps.get_model('typeclasses', 'Attribute') Attribute = apps.get_model('typeclasses', 'Attribute')
ObjectDB = apps.get_model('objects', 'ObjectDB')
PlayerDB = apps.get_model('players', 'PlayerDB')
ScriptDB = apps.get_model('scripts', 'ScriptDB')
HelpEntry = apps.get_model('help', 'HelpEntry')
Msg = apps.get_model('comms', 'Msg')
class Migration(migrations.Migration): class Migration(migrations.Migration):