ok thanks, so you'd rather do it with a Model than a custom field. I actually started to make a custom field but I had a few issues while displaying it in the admin so that's why I asked the question then.
Le jeudi 23 août 2012 00:16:48 UTC+2, Kurtis a écrit : > > Whoops, > > foo = property(get_reference, set_reference) > > should be > > reference = property(get_reference, set_reference) > > Sorry, was reading another page to make sure I have the property code > right: > > http://stackoverflow.com/questions/1454727/do-properties-work-on-django-model-fields > > On Wed, Aug 22, 2012 at 6:15 PM, Kurtis Mullins > <kurtis....@gmail.com<javascript:> > > wrote: > >> It looks like you want to, basically, store a reference to a Python >> object in your Model. It shouldn't be too extremely difficult. I'd create a >> Model for this purpose though and just use extra methods to provide any >> functionality you need. Just as a quick prototypical example: >> >> class ReferenceModel(Model): >> _reference = models.CharField(max_length=150) >> >> def get_reference(self): >> """ >> Load the string from self._reference and use some sort of a >> process >> to dynamically load the object. >> e.g. >> http://stackoverflow.com/questions/547829/how-to-dynamically-load-a-python-class >> """ >> >> def set_reference(self, input): >> self._reference = input >> >> foo = property(get_reference, set_reference) >> >> Anyways, just a guess at one of many ways to possibly accomplish this >> task. >> >> >> On Wed, Aug 22, 2012 at 5:58 PM, Michael Palumbo >> <michael....@gmail.com<javascript:> >> > wrote: >> >>> Hi, >>> >>> Do you know a custom field for a callable python object like a Class or >>> a function ? >>> >>> It could store it as a string in the DB: "module1.module2.class" or >>> "module1.module2.function" >>> With that string, it could load it as a real python object when you get >>> it from the DB. >>> >>> For example, you could do something like that: >>> >>> from module1.module2 import testme >>> mymodel.process = testme >>> mymodel.save() => stores the string "module1.module2.testme" >>> >>> # Later... >>> ins = mymodel.objects.get(..) >>> ins.process('OK') # ins.process can be called because it has been >>> resolved to the testme function >>> >>> Thanks. >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Django users" group. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/django-users/-/sHDfKCKGBmEJ. >>> To post to this group, send email to django...@googlegroups.com<javascript:> >>> . >>> To unsubscribe from this group, send email to >>> django-users...@googlegroups.com <javascript:>. >>> For more options, visit this group at >>> http://groups.google.com/group/django-users?hl=en. >>> >> >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/OK6b72Lrr9gJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.