I want the default modB localField value to be the modA wantedField value 
corresponding to the foreign key. This would gives :

    class modA(models.Model):
        wantedField = models.CharField(max_length=9)
        [ ... other fields ...]
        def asDefault():
            return wantedField

    class modB(models.Model): 
        moda        = models.ForeignKey(modA)
        [ ... other fields ...]
        localField  = models.CharField(max_length=9,default=moda.asDefault)
        def save(self, *args, **kwargs):
            if self.pk is None:
                if self.moda and not self.localField:
                    self.localField = self.moda.wantedField
            super(modB, self).save(*args, **kwargs)

Also, would the approach be the same with any other field type ?
Anyway, for the moment it returns:

    AttributeError: 'ForeignKey' object has no attribute 'asDefault'

Thanks for your help

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/e1ff64e8-4b01-43fb-b651-f8587fb81ee8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to