Re: model validation errors

2009-09-01 Thread alain31

Ok so I will write a custom form.

 I think that I  will also write a custom field to do some specific
things (for example add a url method to get
png ...). I need to understand better the methods :

- contribute_to_class,
-validate, validate_full
-formfield

I found nothing in django's doc, and few examples with google. There
are some usuful stuff in  "pro Django" book
but I'm looking for other doc and examples. In particular, I don't
understand how
validate(self, field_data, all_data) works (how to handle
all_data ?).

I would like to find examples or detailled docs on those topics. If
anyone could point a link ...

Thanks, Alain.



On 1 sep, 14:32, Thomas Guettler  wrote:
> Hi,
>
> Up to now Model Validation is not possible with django. You need to use
> a ModelForm. The documentation contains examples how to do custom validation.
>
> alain31 schrieb:
>
>
>
> > Hello, I wrote a model to manage small TeX fragments:
>
> > class LaTeX(models.Model):
> >     latex = models.TextField(help_text="Un extrait de source LaTeX")
> >     macros = models.ForeignKey(Macros)
>
> > For now, I override save() to compile the latex string using macros
> > strings with LaTeX compilator, and produce a
> > png image that I store with a name made with self.id (so I need to
> > call super...save() before). But in case of
> > LaTeX compilation errors, I just raise an exception that will not
> > appear in production with DEBUG = False.
>
> > I'd like to treat  LaTeX compilation errors as standard validation
> > errors to
> > appear in error list in forms, admin...
>
> >  I don't know how to do this, I looked at
> > - signals (pre-post save) : what about validation ?
> > - write a TextField  subclass and override validate to do compilation
> > here ? But I need to access another field 'macros'  and model.id  ...
> > - I foundhttp://code.djangoproject.com/ticket/6845with a patch to do
> > model validation (1 year ago) that looks
> > like what I need, but is it stable?
>
> --
> Thomas Guettler,http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: model validation errors

2009-09-01 Thread Thomas Guettler

Hi,

Up to now Model Validation is not possible with django. You need to use
a ModelForm. The documentation contains examples how to do custom validation.


alain31 schrieb:
> Hello, I wrote a model to manage small TeX fragments:
> 
> class LaTeX(models.Model):
> latex = models.TextField(help_text="Un extrait de source LaTeX")
> macros = models.ForeignKey(Macros)
> 
> For now, I override save() to compile the latex string using macros
> strings with LaTeX compilator, and produce a
> png image that I store with a name made with self.id (so I need to
> call super...save() before). But in case of
> LaTeX compilation errors, I just raise an exception that will not
> appear in production with DEBUG = False.
> 
> I'd like to treat  LaTeX compilation errors as standard validation
> errors to
> appear in error list in forms, admin...
> 
>  I don't know how to do this, I looked at
> - signals (pre-post save) : what about validation ?
> - write a TextField  subclass and override validate to do compilation
> here ? But I need to access another field 'macros'  and model.id  ...
> - I found http://code.djangoproject.com/ticket/6845 with a patch to do
> model validation (1 year ago) that looks
> like what I need, but is it stable?


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



model validation errors

2009-08-31 Thread alain31

Hello, I wrote a model to manage small TeX fragments:

class LaTeX(models.Model):
latex = models.TextField(help_text="Un extrait de source LaTeX")
macros = models.ForeignKey(Macros)

For now, I override save() to compile the latex string using macros
strings with LaTeX compilator, and produce a
png image that I store with a name made with self.id (so I need to
call super...save() before). But in case of
LaTeX compilation errors, I just raise an exception that will not
appear in production with DEBUG = False.

I'd like to treat  LaTeX compilation errors as standard validation
errors to
appear in error list in forms, admin...

 I don't know how to do this, I looked at
- signals (pre-post save) : what about validation ?
- write a TextField  subclass and override validate to do compilation
here ? But I need to access another field 'macros'  and model.id  ...
- I found http://code.djangoproject.com/ticket/6845 with a patch to do
model validation (1 year ago) that looks
like what I need, but is it stable?

Any hint ?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Model validation errors ...

2006-11-09 Thread ZebZiggle

Ah ... of course.

Thanks James!

Keep up the great work!

-Sandy


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Re: Re: Model validation errors ...

2006-11-09 Thread James Bennett

On 11/9/06, ZebZiggle <[EMAIL PROTECTED]> wrote:
> My question is ... why is Accusation any different tan Message,
> ReadMessage or any of the other tables that relate back to Player?

The problem was that Accusation has *two* fields which relate to
Player. When 'related_name' isn't set, that means that you end up with
two things trying to have an attribute of the same name. Setting
'related_name' clears that up.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Re: Model validation errors ...

2006-11-09 Thread ZebZiggle

More on this:

If I change Accusation to:

class Accusation(models.Model):
game = models.ForeignKey(Game)
player = models.ForeignKey(Player, related_name='related_player')
accusedPlayer = models.ForeignKey(Player,
related_name='related_accusedPlayer')
isCommitted = models.BooleanField()
motive = models.CharField(maxlength = 1024)
method = models.CharField(maxlength = 1024)

then it validates and installs (and the session tables, etc get
installed too)

My question is ... why is Accusation any different tan Message,
ReadMessage or any of the other tables that relate back to Player?

Cheers,
Sandy


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---



Model validation errors ...

2006-11-09 Thread ZebZiggle

Hi there,

I've decided to drop my old 0.91 database and rebuild, rather than try
to upgrade it. So, in my dev environment I've dropped the database, but
now when I try to 'syncdb' I get the following validation error.

Error: Couldn't install apps, because there were errors in one or more
models:
mydarksecret.accusation: Accessor for field 'player' clashes with
related field 'Player.accusation_set'. Add a related_name argument
 to the definition for 'player'.
mydarksecret.accusation: Accessor for field 'accusedPlayer' clashes
with related field 'Player.accusation_set'. Add a related_name a
rgument to the definition for 'accusedPlayer'.

This strikes me as wierd since there are many other tables that have
similar relationships, but it only seems to complain about
'accusation'. See some sample tables below.

Also, I can't seem to get the "django infrastructure" created. syncdb
doesn't want to create them ... is there another manage.py command I
should be using to get things like the session table created?

Any ideas?

Thx,
Sandy

 (partial) MODEL 

class Player(models.Model):
user = models.ForeignKey(User, null = True)
game = models.ForeignKey(Game)
character = models.ForeignKey(GameElement)
joinedOn = models.DateTimeField(auto_now_add = True)

class Message(models.Model):
gameElement = models.ForeignKey(GameElement)
player = models.ForeignKey(Player)
emotion = models.IntegerField()
dateTime = models.DateTimeField(auto_now_add = True)
subject = models.CharField(maxlength = 100)
text = models.CharField(maxlength = 1024)

class ReadMessage(models.Model):
gameElement = models.ForeignKey(GameElement)
player = models.ForeignKey(Player)
dateTime = models.DateTimeField(auto_now_add = True)

class Accusation(models.Model):
game = models.ForeignKey(Game)
player = models.ForeignKey(Player)
accusedPlayer = models.ForeignKey(Player)
isCommitted = models.BooleanField()


--~--~-~--~~~---~--~~
 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
-~--~~~~--~~--~--~---