Hi Seemant, > >http://www.djangoproject.com/documentation/model_api/#unique-togetherI guess > >I must have read the description wrong (I still don't see how > the description implies that a NULL field gets ignored or whatever).
No, you're right that the unique-together description does not explicitly state how NULLs are treated. This mainly stems from the fact that in database-land NULL is really not a value -- it's not even an empty string. NULL denotes the lack of any value. If you want "to_verse" to be part of that 4-way uniqueness constraint and to_verse can indeed be "empty", you could redefine it with a default=0 in your model (you will need to regenerate your model). In essence, you are saying that a NULL to_verse to you is a single value and not a lack of value. So, now when you leave that field blank and save Scripture, to_verse will be stored as 0. This will make your unique_together with the 4 fields work as expected. The caveat is that you will need to a function or property in your model that returns an empty string from to_verse when it's zero. For example (please note that the indentation uses 4 spaces here instead of tabs): def _to_verse(self): return (self.to_verse != 0) and self.to_verse or '' real_to_verse = property_to_verse) The to_verse field in your model will be something like this: to_verse = models.IntegerField (blank = True, null = True, default=0) > > > What happens if you try > > > unique_together = (('book', 'chapter', 'from_verse'), > > ('book', 'chapter', 'from_verse', 'to_verse',))So I > > tried this, but now, after entering Genesis 1:1-2, I can not enter > anything that has Genesis 1:1 in it. So, Genesis 1:1 is "not unique" > apparently, either. > What you are saying is that with the above unique_together spec, Genesis 1:1 becomes unique and therefore Genesis 1:1-2 is not allowed if Genesis 1:1 is already in the DB. In any case, if the default=0 trick works for you, this becomes a moot point. -Rajesh --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---