Re: Overriding save to create and save related entity

2012-07-26 Thread Sithembewena Lloyd Dube
Thanks guys :)

On Wed, Jul 25, 2012 at 6:49 PM, Mattias Linnap  wrote:

> It is possible to override the save() method in a model to add
> functionality:
>
> https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods
>
> Another choice would be to register a receiver for the pre_save or
> post_save signals:
>
> https://docs.djangoproject.com/en/dev/ref/models/instances#what-happens-when-you-save
> https://docs.djangoproject.com/en/dev/topics/signals/
>
> Either method can be used, the choice depends on your desired
> architecture. I prefer overriding save() for changes to the model
> itself or its related models (as in this case), and signals less
> related features (for example sending an email).
>
> On Wed, Jul 25, 2012 at 4:34 PM, Sithembewena Lloyd Dube
>  wrote:
> > Hi all,
> >
> > I have the following code:
> >
> > class Points(models.Model):
> >  blah blah
> >
> > class TrainingSession(models.Model):
> > confirmed = models.BooleanField()
> > points = models.ForeignKey(Points, null=True, blank=True)
> >
> > When a training session is saved, if confirmed is True I wish to create
> and
> > save a points instance. How can I do so?
> >
> >
> > --
> > Regards,
> > Sithembewena Lloyd Dube
> >
> > --
> > 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.
>
> --
> 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.
>
>


-- 
Regards,
Sithembewena Lloyd Dube

-- 
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: Overriding save to create and save related entity

2012-07-25 Thread Mattias Linnap
It is possible to override the save() method in a model to add functionality:
https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

Another choice would be to register a receiver for the pre_save or
post_save signals:
https://docs.djangoproject.com/en/dev/ref/models/instances#what-happens-when-you-save
https://docs.djangoproject.com/en/dev/topics/signals/

Either method can be used, the choice depends on your desired
architecture. I prefer overriding save() for changes to the model
itself or its related models (as in this case), and signals less
related features (for example sending an email).

On Wed, Jul 25, 2012 at 4:34 PM, Sithembewena Lloyd Dube
 wrote:
> Hi all,
>
> I have the following code:
>
> class Points(models.Model):
>  blah blah
>
> class TrainingSession(models.Model):
> confirmed = models.BooleanField()
> points = models.ForeignKey(Points, null=True, blank=True)
>
> When a training session is saved, if confirmed is True I wish to create and
> save a points instance. How can I do so?
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
>
> --
> 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.

-- 
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: Overriding save to create and save related entity

2012-07-25 Thread Nicolas Emiliani
On Wed, Jul 25, 2012 at 12:34 PM, Sithembewena Lloyd Dube  wrote:

> Hi all,
>
> I have the following code:
>
> class Points(models.Model):
>  blah blah
>
> class TrainingSession(models.Model):
> confirmed = models.BooleanField()
> points = models.ForeignKey(Points, null=True, blank=True)
>
> When a training session is saved, if confirmed is True I wish to create
> and save a points instance. How can I do so?
>

You can override the save_model method at the ModelAdmin

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model


>
> --
> Regards,
> Sithembewena Lloyd Dube
>
> --
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



Overriding save to create and save related entity

2012-07-25 Thread Sithembewena Lloyd Dube
Hi all,

I have the following code:

class Points(models.Model):
 blah blah

class TrainingSession(models.Model):
confirmed = models.BooleanField()
points = models.ForeignKey(Points, null=True, blank=True)

When a training session is saved, if confirmed is True I wish to create and
save a points instance. How can I do so?


-- 
Regards,
Sithembewena Lloyd Dube

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