Friday, November 23, 2012

overwrite field value in subclasses

Hi all,

One piece of my model is as follow :

class UpperAbstract(models.Model):
  CHOICE_A = 0
  CHOICE_B = 1
  CHOICE_C = 2
  myfield = models.PositiveSmallIntegerField(choices=((CHOICE_A,'A'),(CHOICE_B,"B"),(CHOICE_C,"C")),blank=False)
  class Meta:
abstract = True

class Foo(UpperAbstract):
      myfield = UpperAbstract.CHOICE_A



I am expecting any instance of Foo being created, to have 'myfield' always and "automatically" set to UpperAbstract.CHOICE_A
In my test the created object as null value and saving it is refused on IntegrityError because 'myfield' cannot be None

thank in advance for any help.
regards

manu





--
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/-/pUf-aX6JrycJ.
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