Hey Marcos, In the clean() method of my ClipModelForm class I couldn't manage how to reach the ClipDescriptions that are coming from the inline ClipDescriptionInline. I think I can't validate there. I spent the whole day trying and I couldn't fix. Any help would be very handy!
Thanks for your atention. Kind regards, Gabriel Gabriel de Carvalho Nogueira Reis Software Developer +44 7907 823942 On Fri, Jan 15, 2010 at 4:45 PM, Marco Rogers <marco.rog...@gmail.com>wrote: > I've never had to do this but it sounds you want to work with > Form.clean() in stead of Form.clean_is_approved(). From the docs: > > "The Form subclass’s clean() method. This method can perform any > validation that requires access to multiple fields from the form at > once." > > So in your clean method you would grab the submitted inlines and check > them against the is_approved field on the Clip. I'm not a django > expert, but that's where I would start. Good luck. > > :Marco > > > On Jan 14, 6:45 pm, Gabriel Reis <gabriel...@gmail.com> wrote: > > Hi people, > > > > I am having some problem to validate a data in my application. I will try > to > > simply the model in here to help you guys to understand the problem. > > I have 2 models: > > > > class Clip(models.Model): > > is_approved = models.BooleanField(default=False) > > language = models.ForeignKey(Language) > > > > class ClipDescription(models.Model): > > clip = models.ForeignKey(Clip) > > text = models.TextField() > > language = models.ForeignKey(Language) > > > > I am editing via ModelAdmin. I defined a ClipModelAdmin class as above > > (simplified): > > > > class ClipAdmin(admin.ModelAdmin): > > inlines = [ > > ClipDescriptionInline > > ] > > > > So, as you can see, both Clip and ClipDescription are edited in the same > > page (using the 'inlines' feature). > > > > But the rule is: if the user trigger the 'Save' action, the attribute > > Clip.is_approved can be True only if there is a ClipDescription instance > > associated to the Clip instance, having the same language. For example, > if I > > have a clip with id=1, language=english and is_approved=True, it can be > > saved only if there is a clip description with clip_id=1, > language=english. > > If not, I want to show the error message 'Cannot approve this clip > without > > having a description in English' in the form. > > > > I have already read the official documentation and tried to work with > > validators, tried to define a ModelForm and its clean_is_approved method, > > among other workarounds. And I still couldn't make this work. The problem > is > > at the clean_is_approved context I couldn't figure out how to get access > to > > the form data that is being entered at that moment, to retrieve the Clip > > descriptions. > > > > I don't if I was clear enough, I can give more details. Any ideas and > > suggestions will be very appreciated. > > > > Thank you very much for your attention. > > > > Kind regards, > > > > Gabriel > > > > Gabriel de Carvalho Nogueira Reis > > Software Developer > > +44 7907 823942 > > -- > 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<django-users%2bunsubscr...@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.