Hi guys,
now this is kind of hard for me to explain, I hope that somebody
understands what I actually want.
I am a python newbie and wonder if there is an easy solution.
*They say: DRY!!*
*My question is:How do a define an (abstract?) class including methods and
fieldsand then attach it to a real mode with variants instants?*
*The data needs to be available as realy models.* types, so I can use it in
forms.*
Hopefully this example makes it clear:
# I would love to keep it DRY and wonder if there is a solution for this in
python?
# NOW THIS IS TOTALLY MADE UP
# Basically I would like to be able to define a definition of model-fields
and functions
# and then be able to "attach" it to a model as various instances
class KidType (models.Model):
NAMEHOLDER = '' #nameholder
NAMEHOLDER_text = models.TextField()
NAMEHOLDER_timestamp_updated = models.DateTimeField(auto_now_add=False,
auto_now=True)
def example_function_shared_among_types():
return str(self.NAMEHOLDER_text + self.NAMEHOLDER_timestamp_updated)
def set_NAMEHOLDER_text(value):
self.set_NAMEHOLDER_text(value)
#
class DataHolderModel(models.Model):
# Attach the above definition with different names
# and make them accessable
@attach (KidType, KidType.NAME = 'dataset1')
@attach (KidType, KidType.NAME = 'dataset2')
@attach (KidType, KidType.NAME = 'dataset3')
# Access the instances within the HolderModel:
data_holder = DataHolderModel()
data_holder.dataset1_text = 'value1'
data_holder.set_dataset1_text('value1')
data_holder.dataset2_text = 'value2'
data_holder.dataset3_text = 'value3'
Any ideas? Can I do something like this?
I am really thankful for your tips
Thomas
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/defa37b3-ae0f-4518-8c6c-bfd99a01ccc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.