Doesn't this do what you want?: class MyModel(models.Model): weight = .. height = ... width = ... length = ...
def clean(self): from django.core.exceptions import ValidationError if self.weight or self.height or self.width or self.length and not (self.weight and self.height and self.width and self.length): raise ValidationError("Sorry, in order to use weight, height, width, or" " length, you have to include them all.") def save(self, *args, **kwargs): self.clean() super(MyModel, self).save(*args, **kwargs) Of course it does require you to write a little more code, but it is possible. Besides, does the required_together mean that all fields are required when one is filled out, or that some are required when the first is filled out? What I mean is that there are many possibilities for validating a model, and at the moment we have quite some good tools for them. Adding another Meta option for a small portion of the cases doesn't seem so necessary to me... Anyway, that's just my 2c. TinO On Sun, Oct 3, 2010 at 05:58, LookMa NoSQL <lookmano...@gmail.com> wrote: > +1 on proposal (for what it matters). > > Tina, where did you see that Django does that? The docs link you sent > shows regular model validation. What Mamayo is looking for, I think, > is the ability to add a Meta option to a model that says > required_together=({fields: ('weight', 'height', 'width', 'length'), > error_message: "Sorry, in order to use weight, height, width, or > length, you have to include them all."}). At least I think that's what > he means. This would help me too. > > On Oct 2, 10:17 am, TiNo <tin...@gmail.com> wrote: > > Hi, > > > > Isn't this covered by model validation [1]? > > > > Tino > > > > [1] > http://docs.djangoproject.com/en/dev/ref/models/instances/#validating... > > > > On Fri, Oct 1, 2010 at 15:59, hejsan <hr.bja...@gmail.com> wrote: > > > Hi. > > > I just filed a feature request on the same or similar issue, and this > > > thread was brought to my attention: > > >http://code.djangoproject.com/ticket/14347 > > > > > Basically the usecase is this: > > > Very often we have a "Published" field on our models (or "Published > > > date" or "Published status" etc..) It would be very nice to be able to > > > allow people to save instances without all the required fields being > > > filled in IF the article or whathaveyou is not published yet. > > > > > My suggestion was to allow the "required" field on the form field to > > > take a callable instead of a boolean. > > > In this callable we could check whether some other fields are filled > > > out or whatever we want. > > > > > This would be a very handy feature for a very common problem. > > > > > best, > > > Hejsan > > > > > On Sep 27, 7:34 am, Yo-Yo Ma <baxterstock...@gmail.com> wrote: > > > > Thanks, David. I've read some about the "Custom validation error on > > > > unique_together" ticket. I imagine that if people want customization > > > > there, required_together would need the same. The only idea I have > > > > that seems to work for both situations is: > > > > > > required_together = (('weight', 'height', 'You must provide a weight > > > > and height, if you intend to use either.'),) > > > > > > unique_together = (('account', 'sku', 'This sku is already in use by > > > > your company.'),) > > > > > > On Sep 27, 1:22 am, "David P. Novakovic" <davidnovako...@gmail.com> > > > > wrote: > > > > > > > Is it? I read this as different to anything in the ORM. > > > > > > > This is about conditionally requiring a second field if one is > filled > > > > > out. Normally it would be done at the JS level. > > > > > > > I think it's a good idea, assuming I haven't missed something that > > > > > already does this. > > > > > > > I can't help thinking this is part of a much larger problem though. > > > > > That problem is multifield validation. I think we'd have to address > > > > > that issue first before working on this specific case that is > probably > > > > > the simplest. > > > > > > > Maybe this has been considered before, but was dropped because the > > > > > idea is too hard to encapsulate in a simple Meta style option? > > > > > > > David > > > > > > > On Mon, Sep 27, 2010 at 5:18 PM, Florian Apolloner > > > > > > > <f.apollo...@gmail.com> wrote: > > > > > > Please post usage questions to the users list. This is already > doable > > > > > > with model validation. > > > > > > > > Florian > > > > > > > > -- > > > > > > You received this message because you are subscribed to the > Google > > > Groups "Django developers" group. > > > > > > To post to this group, send email to > > > django-develop...@googlegroups.com. > > > > > > To unsubscribe from this group, send email to > > > django-developers+unsubscr...@googlegroups.com<django-developers%2bunsubscr...@googlegroups.com> > <django-developers%2bunsubscr...@googlegroups.com<django-developers%252bunsubscr...@googlegroups.com> > > > > > . > > > > > > For more options, visit this group athttp:// > > > groups.google.com/group/django-developers?hl=en. > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Django developers" group. > > > To post to this group, send email to > django-develop...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-developers+unsubscr...@googlegroups.com<django-developers%2bunsubscr...@googlegroups.com> > <django-developers%2bunsubscr...@googlegroups.com<django-developers%252bunsubscr...@googlegroups.com> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/django-developers?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To post to this group, send email to django-develop...@googlegroups.com. > To unsubscribe from this group, send email to > django-developers+unsubscr...@googlegroups.com<django-developers%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-developers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.