Re: overriding save-method

2010-10-30 Thread skyjur
Write a custom model field: http://docs.djangoproject.com/en/dev/howto/custom-model-fields/ Or even better, take already written one: http://djangosnippets.org/snippets/377/ On Oct 27, 9:14 am, Patrick wrote: > hi, > > i am trying to override the save-method of one of my models. i want to > save

Re: overriding save-method

2010-10-28 Thread Patrick
that's how i did it finally... i had to refresh my knowledge about the property statement first :) thanks again! class Setting(models.Model): name = models.CharField(max_length=100) _value_json = models.TextField() def _set_json_value(self, value): self._value_json = json.dumps

Re: overriding save-method

2010-10-27 Thread Patrick
hm .. i thought of that too but i considered it not to be the best approach. i will try that snippet though.. thank you! On 27 Okt., 15:49, Shawn Milochik wrote: > Try this instead: > > http://djangosnippets.org/snippets/1478/ > > Or you could do it manually in your model: > > 1. Add field _value

Re: overriding save-method

2010-10-27 Thread Shawn Milochik
Try this instead: http://djangosnippets.org/snippets/1478/ Or you could do it manually in your model: 1. Add field _value_json to your model. 2. Add functions (get_value, set_value) which do the simplejson work. 3. Add a property named 'value' with get_value and set_value as its getter and sette

overriding save-method

2010-10-27 Thread Patrick
hi, i am trying to override the save-method of one of my models. i want to save the json-representation of any object in a text field. somehow it doesn't seem to work. class Setting(models.Model): name = models.CharField(max_length=100) value = models.TextField() def save(self, *args

Model super class with overriding save method

2010-05-30 Thread Amit Prahesh
Hi, because of hysterical raisins I need that the models of a simple app I was tasked upon have their primary fields to consist of strings of randomly generated characters (think something like '876nce8yr85yndxw45') of a given length. I'm trying to create a super class that provides this facility,

Re: Overriding save() method on models to automatically add ManyToMany relationship

2009-06-09 Thread ringemup
No, you have to save self before you can add categories to it, because you can't save an M2M if either object is missing a primary key. In any case, it turns out that the reason is that the admin saves the submitted M2M data after the save() method is called on the main model. So it erases and

Re: Overriding save() method on models to automatically add ManyToMany relationship

2009-06-09 Thread Frédéric Hébert
Hi, > defsave(self, *args): >    models.Model(save, *args) >    category = Category.objects.all()[0] >    self.categories.add(category) > > This does not work, I'm sure it's saving ManyToMany relationships > later on in thesaveprocess.  Is there a way to make this work? > IMHO, it's make sense :

Re: Overriding save() method on models to automatically add ManyToMany relationship

2009-05-24 Thread ringemup
I'm encountering this same problem. Did you ever find a solution? On Apr 27, 1:38 pm, Adam Olsen wrote: > On Mon, Apr 27, 2009 at 11:27 AM, Alex Gaynor wrote: > > The issues if the method, it's nonsensical and doesn't correspond to > > anything(you are instantiating models.Model with save as t

Re: Problem with overriding save() method

2009-05-07 Thread George Song
On 5/7/2009 8:05 AM, Lee Hinde wrote: > On Wed, May 6, 2009 at 11:37 PM, George Song wrote: >> On 5/6/2009 11:18 PM, Lee Hinde wrote: >>> On Wed, May 6, 2009 at 11:15 PM, Lee Hinde wrote: On Wed, May 6, 2009 at 10:54 PM, George Song wrote: > On 5/6/2009 10:34 PM, Lee Hinde wrote: >

Re: Problem with overriding save() method

2009-05-07 Thread Lee Hinde
On Wed, May 6, 2009 at 11:37 PM, George Song wrote: > > On 5/6/2009 11:18 PM, Lee Hinde wrote: >> On Wed, May 6, 2009 at 11:15 PM, Lee Hinde wrote: >>> On Wed, May 6, 2009 at 10:54 PM, George Song wrote: On 5/6/2009 10:34 PM, Lee Hinde wrote: > On Wed, May 6, 2009 at 10:22 PM, George S

Re: Problem with overriding save() method

2009-05-06 Thread George Song
On 5/6/2009 11:18 PM, Lee Hinde wrote: > On Wed, May 6, 2009 at 11:15 PM, Lee Hinde wrote: >> On Wed, May 6, 2009 at 10:54 PM, George Song wrote: >>> On 5/6/2009 10:34 PM, Lee Hinde wrote: On Wed, May 6, 2009 at 10:22 PM, George Song wrote: > On 5/6/2009 9:57 PM, Lee Hinde wrote: >

Re: Problem with overriding save() method

2009-05-06 Thread Lee Hinde
On Wed, May 6, 2009 at 11:15 PM, Lee Hinde wrote: > On Wed, May 6, 2009 at 10:54 PM, George Song wrote: >> >> On 5/6/2009 10:34 PM, Lee Hinde wrote: >>> On Wed, May 6, 2009 at 10:22 PM, George Song wrote: On 5/6/2009 9:57 PM, Lee Hinde wrote: > I have this as part of the model for a cl

Re: Problem with overriding save() method

2009-05-06 Thread Lee Hinde
On Wed, May 6, 2009 at 10:54 PM, George Song wrote: > > On 5/6/2009 10:34 PM, Lee Hinde wrote: >> On Wed, May 6, 2009 at 10:22 PM, George Song wrote: >>> On 5/6/2009 9:57 PM, Lee Hinde wrote: I have this as part of the model for a class called "Class"     def save(self, force

Re: Problem with overriding save() method

2009-05-06 Thread George Song
On 5/6/2009 10:34 PM, Lee Hinde wrote: > On Wed, May 6, 2009 at 10:22 PM, George Song wrote: >> On 5/6/2009 9:57 PM, Lee Hinde wrote: >>> I have this as part of the model for a class called "Class" >>> >>> >>> def save(self, force_insert=False, force_update=False): >>> start = default

Re: Problem with overriding save() method

2009-05-06 Thread Lee Hinde
On Wed, May 6, 2009 at 10:22 PM, George Song wrote: > > On 5/6/2009 9:57 PM, Lee Hinde wrote: >> I have this as part of the model for a class called "Class" >> >> >>     def save(self, force_insert=False, force_update=False): >>         start = defaultfilters.slugify(self.Name) >>         count =

Re: Problem with overriding save() method

2009-05-06 Thread George Song
On 5/6/2009 9:57 PM, Lee Hinde wrote: > I have this as part of the model for a class called "Class" > > > def save(self, force_insert=False, force_update=False): > start = defaultfilters.slugify(self.Name) > count = Class.objects.filter(Slug__equal=start).count() > if

Problem with overriding save() method

2009-05-06 Thread Lee Hinde
I have this as part of the model for a class called "Class" def save(self, force_insert=False, force_update=False): start = defaultfilters.slugify(self.Name) count = Class.objects.filter(Slug__equal=start).count() if count != 0: filterme = "%s_%d" % (self.

Re: Overriding save method in model

2009-05-06 Thread Thierry
I don't exactly want to save the full path of the image in the database, just the image extension. I am trying to convert the current implementation of a PHP web page to Django. Here's how the table looks like, I'll be more explicit with the img ext this time: idname img_ext --

Re: Overriding save method in model

2009-05-06 Thread Daniel Roseman
On May 5, 10:15 pm, Thierry wrote: > How can I set picture to the image extension?  I don't think > "instance.picture = ext" works: > >  def pet_picture_upload(instance, filename): >      name, ext = os.path.splitext(filename) >      instance.picture = ext >      return '/usr/django/images/%s%s'

Re: Overriding save method in model

2009-05-05 Thread Thierry
How can I set picture to the image extension? I don't think "instance.picture = ext" works: def pet_picture_upload(instance, filename): name, ext = os.path.splitext(filename) instance.picture = ext return '/usr/django/images/%s%s' % (instance.pk, ext) On May 5, 3:48 pm, Daniel R

Re: Overriding save method in model

2009-05-05 Thread Daniel Roseman
On May 5, 8:00 pm, Thierry wrote: > I have the following model: > > class Pet(models.Model): >     name = models.CharField(max_length=64) >     picture = models.ImageField(upload_to='/usr/django/images/') > >     def save(self, force_insert=False, force_update=False): >         // override the pi

Overriding save method in model

2009-05-05 Thread Thierry
I have the following model: class Pet(models.Model): name = models.CharField(max_length=64) picture = models.ImageField(upload_to='/usr/django/images/') def save(self, force_insert=False, force_update=False): // override the picture values super(Pet, self).save(force_

Re: Overriding save() method on models to automatically add ManyToMany relationship

2009-04-27 Thread Adam Olsen
On Mon, Apr 27, 2009 at 11:27 AM, Alex Gaynor wrote: > The issues if the method, it's nonsensical and doesn't correspond to > anything(you are instantiating models.Model with save as the first > argument), in Python the correct way to call the parent class's method is: > > super(MyClass, self).s

Re: Overriding save() method on models to automatically add ManyToMany relationship

2009-04-27 Thread Alex Gaynor
On Mon, Apr 27, 2009 at 1:24 PM, Adam Olsen wrote: > > I've got two models, something like this: > > class Category(models.Model): >name = models.CharField(max_length=60) > > class Product(models.Model): >sku = models.CharField(max_length=20) >categories = models.ManyToManyField(Categ

Overriding save() method on models to automatically add ManyToMany relationship

2009-04-27 Thread Adam Olsen
I've got two models, something like this: class Category(models.Model): name = models.CharField(max_length=60) class Product(models.Model): sku = models.CharField(max_length=20) categories = models.ManyToManyField(Category) I want to overload the save method to automatically add cer