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
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
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
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
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
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,
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
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 :
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
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:
>
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
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:
>
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
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
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
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 =
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
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.
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
--
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'
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
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
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_
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
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
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
26 matches
Mail list logo