Hi Alex,
I think this is what you might be looking for.
class Something(models.Model):
def __init__(self, *args, **kwargs):
if kwargs.has_key('range_marks'):
_choices = kwargs.get('range_marks')
del kwargs['range_marks']
else:
_choices = (('default', 'default'), )
self.range_marks = models.IntegerField(choices = _choices,
verbose_name = 'Marks of Something')
super(Something, self).__init__(*args, **kwargs)
Let us know if it works :)
Cheers
Cal
On 02/12/2010 06:53, Alex Boyko wrote:
Hi!
I got such kind of problem.
I'd like to define the tuple(list) of choices option at the moment of
instance created on the fly
In the future these choices will not change.
Hence I've found just one way to do it - override __init__() of my
model and
pass there the particular predefined list of choices that depends on
current model's instance (in code - 'range_list')
But this approach seems doesn't work properly.
Would You be so kind to help with advice - how I can solve my task
with dynamical choices per model's instance.
---------------------------------------
RANGE_CHOICES = ()
class Something(models.Model):
def __init__(self, *args, **kwargs):
range = kwargs.pop('range_list', None)
super(Covenant, self).__init__(*args, **kwargs)
self._meta.get_field_by_name('range_marks')[0]._choices = range
range_marks = models.IntegerField(choices = RANGE_CHOICES,
verbose_name = 'Marks of Something')
-----------------------------------------
Thanks in Advance!
Best Regards!
Alex
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To post to this group, send email to django-us...@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.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-us...@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.