Hello,

Having the following (Postgre)SQL statement:

CREATE TABLE Games (
  minPlayer integer NOT NULL DEFAULT 1,
  maxPlayer integer NOT NULL DEFAULT 1,
  CHECK (min_player <= max_player)
)

the consequent Model for Django would be:

class Game(model.Models):
  min_player = models.IntegerField(default=1),
  max_player = models.IntegerField(default=1)

But how can I define the "CHECK (min_player <= max_player)"
constraint? I tried overriding the save method to:

def save(self):
  if self.max_player < self.min_player:
    return False
  super(Game, self).save()

and although no game will be created (when specifying max_player <
min_player), the Admin interface will output a successful creation to
the user, when it is not.

Workarounds any?

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to