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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment