Added Tag inlines in for ObjectDB admin. Fixed issue with tag addition.
This commit is contained in:
parent
b0bf60cda4
commit
1da88deb93
2 changed files with 11 additions and 5 deletions
|
|
@ -12,13 +12,15 @@ from src.typeclasses.models import Tag, LiteAttribute
|
||||||
|
|
||||||
|
|
||||||
class AttributeInline(admin.TabularInline):
|
class AttributeInline(admin.TabularInline):
|
||||||
|
# This class is currently not used, because PickleField objects are not editable.
|
||||||
|
# It's here for us to ponder making a way that allows them to be edited.
|
||||||
model = Attribute
|
model = Attribute
|
||||||
fields = ('db_key', 'db_value')
|
fields = ('db_key', 'db_value')
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
class TagInline(admin.TabularInline):
|
class TagInline(admin.TabularInline):
|
||||||
model = Tag
|
model = ObjectDB.db_tags.through
|
||||||
fields = ('db_key', 'db_category', 'db_data')
|
raw_id_fields = ('tag',)
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
class LiteAttributeInline(admin.TabularInline):
|
class LiteAttributeInline(admin.TabularInline):
|
||||||
|
|
@ -26,6 +28,9 @@ class LiteAttributeInline(admin.TabularInline):
|
||||||
fields = ('db_key', 'db_category', 'db_data')
|
fields = ('db_key', 'db_category', 'db_data')
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
class TagAdmin(admin.ModelAdmin):
|
||||||
|
fields = ('db_key', 'db_category', 'db_data')
|
||||||
|
|
||||||
class ObjectCreateForm(forms.ModelForm):
|
class ObjectCreateForm(forms.ModelForm):
|
||||||
"This form details the look of the fields"
|
"This form details the look of the fields"
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -83,7 +88,7 @@ class ObjectDBAdmin(admin.ModelAdmin):
|
||||||
)
|
)
|
||||||
|
|
||||||
#deactivated temporarily, they cause empty objects to be created in admin
|
#deactivated temporarily, they cause empty objects to be created in admin
|
||||||
#inlines = [AliasInline, AttributeInline]
|
inlines = [TagInline]
|
||||||
|
|
||||||
|
|
||||||
# Custom modification to give two different forms wether adding or not.
|
# Custom modification to give two different forms wether adding or not.
|
||||||
|
|
@ -125,3 +130,4 @@ class ObjectDBAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(ObjectDB, ObjectDBAdmin)
|
admin.site.register(ObjectDB, ObjectDBAdmin)
|
||||||
|
admin.site.register(Tag, TagAdmin)
|
||||||
|
|
@ -97,7 +97,7 @@ class Attribute(SharedMemoryModel):
|
||||||
# Attribute Database Model setup
|
# Attribute Database Model setup
|
||||||
#
|
#
|
||||||
# These database fields are all set using their corresponding properties,
|
# These database fields are all set using their corresponding properties,
|
||||||
# named same as the field, but withtout the db_* prefix.
|
# named same as the field, but without the db_* prefix.
|
||||||
db_key = models.CharField('key', max_length=255, db_index=True)
|
db_key = models.CharField('key', max_length=255, db_index=True)
|
||||||
# access through the value property
|
# access through the value property
|
||||||
db_value = PickledObjectField('value', null=True)
|
db_value = PickledObjectField('value', null=True)
|
||||||
|
|
@ -367,7 +367,7 @@ class TagHandler(object):
|
||||||
"Add a new tag to the handler"
|
"Add a new tag to the handler"
|
||||||
for tag in make_iter(tag):
|
for tag in make_iter(tag):
|
||||||
tag = tag.strip().lower() if tag!=None else None
|
tag = tag.strip().lower() if tag!=None else None
|
||||||
category = "%s%s" % (self.prefix, category.strip.lower()) if category!=None else None
|
category = "%s%s" % (self.prefix, category.strip().lower()) if category!=None else None
|
||||||
data = str(data) if data!=None else None
|
data = str(data) if data!=None else None
|
||||||
# this will only create tag if no matches existed beforehand (it will overload
|
# this will only create tag if no matches existed beforehand (it will overload
|
||||||
# data on an existing tag since that is not considered part of making the tag unique)
|
# data on an existing tag since that is not considered part of making the tag unique)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue