mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 01:36:32 +01:00
Small cleanup
This commit is contained in:
parent
948c11dc36
commit
0757bddb05
1 changed files with 5 additions and 56 deletions
|
|
@ -160,10 +160,10 @@ class AttributeForm(forms.ModelForm):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
If we have a tag, then we'll prepopulate our instance with the fields we'd expect it
|
||||
to have based on the tag. tag_key, tag_category, tag_type, and tag_data all refer to
|
||||
the corresponding tag fields. The initial data of the form fields will similarly be
|
||||
populated.
|
||||
If we have an Attribute, then we'll prepopulate our instance with the fields we'd expect it
|
||||
to have based on the Attribute. attr_key, attr_category, attr_value, attr_strvalue, attr_type,
|
||||
and attr_lockstring all refer to the corresponding Attribute fields. The initial data of the form fields will
|
||||
similarly be populated.
|
||||
"""
|
||||
super(AttributeForm, self).__init__(*args, **kwargs)
|
||||
attr_key = None
|
||||
|
|
@ -250,7 +250,7 @@ class AttributeFormSet(forms.BaseInlineFormSet):
|
|||
|
||||
class AttributeInline(admin.TabularInline):
|
||||
"""
|
||||
A handler for inline Tags. This class should be subclassed in the admin of your models,
|
||||
A handler for inline Attributes. This class should be subclassed in the admin of your models,
|
||||
and the 'model' and 'related_field' class attributes must be set. model should be the
|
||||
through model (ObjectDB_db_tag', for example), while related field should be the name
|
||||
of the field on that through model which points to the model being used: 'objectdb',
|
||||
|
|
@ -280,56 +280,5 @@ class AttributeInline(admin.TabularInline):
|
|||
ProxyFormset.related_field = self.related_field
|
||||
return ProxyFormset
|
||||
|
||||
# class AttributeInline(admin.TabularInline):
|
||||
# """
|
||||
# Inline creation of player attributes.j
|
||||
#
|
||||
# """
|
||||
# # Set this to the through model of your desired M2M when subclassing.
|
||||
# model = None
|
||||
# extra = 1
|
||||
# # form = AttributeForm
|
||||
# fields = ('attribute', 'key', 'value', 'strvalue')
|
||||
# raw_id_fields = ('attribute',)
|
||||
# readonly_fields = ('key', 'value', 'strvalue')
|
||||
#
|
||||
# def key(self, instance):
|
||||
# if not instance.id:
|
||||
# return "Not yet set or saved."
|
||||
# return '<strong><a href="%s">%s</a></strong>' % (
|
||||
# reverse("admin:typeclasses_attribute_change",
|
||||
# args=[instance.attribute.id]),
|
||||
# instance.attribute.db_key)
|
||||
#
|
||||
# key.allow_tags = True
|
||||
#
|
||||
# def value(self, instance):
|
||||
# if not instance.id:
|
||||
# return "Not yet set or saved."
|
||||
# return instance.attribute.value
|
||||
#
|
||||
# def strvalue(self, instance):
|
||||
# if not instance.id:
|
||||
# return "Not yet set or saved."
|
||||
# return instance.attribute.strvalue
|
||||
|
||||
|
||||
class AttributeAdmin(ModelAdmin):
|
||||
"""
|
||||
Defines how to display the attributes.
|
||||
|
||||
"""
|
||||
search_fields = ('db_key', 'db_category')
|
||||
list_display = ('db_key', 'db_strvalue', 'db_value')
|
||||
permitted_types = ('str', 'unicode', 'int', 'float', 'NoneType', 'bool')
|
||||
|
||||
fields = ('db_key', 'db_value', 'db_strvalue', 'db_category',
|
||||
'db_lock_storage', 'db_model', 'db_attrtype')
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
if obj.db_value.__class__.__name__ not in self.permitted_types:
|
||||
return ['db_value']
|
||||
return []
|
||||
|
||||
admin.site.register(Attribute, AttributeAdmin)
|
||||
admin.site.register(Tag, TagAdmin)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue