On 10/02/2019 6:22 pm, Nick Emery wrote:
I am trying to wrap up my first app using Django (specifically Django
Rest Framework which may change the save behavior), but have run into
an issue that I haven't been able to solve for about 10 hours now.
I am trying to override the save() method of a
UPDATE: Finally figured it out! I ultimately did this by overriding
`perform_create()` in my [Django Rest Framework
view](https://www.django-rest-framework.org/api-guide/generic-views/) and
making my changes after saving the object.
On Sunday, February 10, 2019 at 8:34:44 AM UTC-5, Nick Emery w
The child objects are created separately beforehand with NULL parents (they
don't have to have parents, they can be orphans). One other thing I noticed
is that looking at the SQL statements executed by my app I can't even see
the UPDATE on the foreign keys of the children (even though I KNOW it'
And how?
On Sun, 10 Feb, 2019, 9:23 PM Shashank Singh When do you create child objects??
>
> On Sun, 10 Feb, 2019, 9:17 PM Nick Emery
>> Tried this too but save() never actually gets called on the child (it
>> seems that the foreign key field of the child is updated at the database
>> level and
When do you create child objects??
On Sun, 10 Feb, 2019, 9:17 PM Nick Emery Tried this too but save() never actually gets called on the child (it
> seems that the foreign key field of the child is updated at the database
> level and never goes through the Django orm Child).
>
> On Sunday, Februar
Tried this too but save() never actually gets called on the child (it seems
that the foreign key field of the child is updated at the database level
and never goes through the Django orm Child).
On Sunday, February 10, 2019 at 8:37:54 AM UTC-5, Shashank Singh wrote:
>
> Override the save() of th
Override the save() of the child?
On Sun, 10 Feb, 2019, 7:04 PM Nick Emery I am trying to wrap up my first app using Django (specifically Django
> Rest Framework which may change the save behavior), but have run into an
> issue that I haven't been able to solve for about 10 hours now.
>
> I am tr
I am trying to wrap up my first app using Django (specifically Django Rest
Framework which may change the save behavior), but have run into an issue
that I haven't been able to solve for about 10 hours now.
I am trying to override the save() method of a model to modify a field on a
bunch of chi
lt-in, Pythonic way of parsing URLs.
>
>
>
> *From:* django...@googlegroups.com [mailto:
> django...@googlegroups.com ] *On Behalf Of *cale...@gmail.com
>
> *Sent:* Wednesday, January 16, 2019 11:07 AM
> *To:* Django users
> *Subject:* Re: Overriding Save in Model
&
URLs.
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On
Behalf Of caleor...@gmail.com
Sent: Wednesday, January 16, 2019 11:07 AM
To: Django users
Subject: Re: Overriding Save in Model
thanks, i've got tldextract which is sufficient for splitting the domain up
hon.org/3/library/urllib.parse.html
>
>
>
>
>
> *From:* django...@googlegroups.com [mailto:
> django...@googlegroups.com ] *On Behalf Of *cale...@gmail.com
>
> *Sent:* Wednesday, January 16, 2019 10:41 AM
> *To:* Django users
> *Subject:* Overriding Save i
Check out urllib.parse.
https://docs.python.org/3/library/urllib.parse.html
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On
Behalf Of caleor...@gmail.com
Sent: Wednesday, January 16, 2019 10:41 AM
To: Django users
Subject: Overriding Save in Model
I'm tryi
I'm trying to extract an entered domain name and split it up so that i can
store unique domains in a specific table
The flow
user will enter website address > model takes website address > splits it
into sub_domain, domain and suffix and stores the values in the appropriate
split fields
so far
On Sunday, December 9, 2012 9:08:18 PM UTC-8, Mike Dewhirst wrote:
>
> On 10/12/2012 10:59am, Victor Hooi wrote:
> > Also - in terms of using them with QuerySets - there aren't any
> > workarounds to use model methods with QuerySets are there? It seems like
> > that would be a definite argument
an exactly here but you can use them in model
methods. Use the class manager.
ClassName.objects.filter(thing=self.this, whatever=self.that, etc=etc)
Finally - thanks for the tip about signals() - so should I be using
something like django.db.models.signals.post_save in addition to
overriding
so should I be using
something like django.db.models.signals.post_save in addition to overriding
save(), or instead of it?
Cheers,
Victor
On Monday, 10 December 2012 10:49:22 UTC+11, Chris Cogdon wrote:
>
> Even though I'm a total database junkie (and where by that I mean
> postg
Even though I'm a total database junkie (and where by that I mean
postgresql > mysql :) ), I have to agree with Mike. If you can keep it in
the model layer, do that. Once you start putting optimisations into the
database layer, you lose a lot of portability between databases: there is
no such t
On 9/12/2012 5:54pm, Thomas Lockhart wrote:
On 12/8/12 5:37 AM, Derek wrote:
Rather than use a trigger (which is DB-specific and also hard to debug
because not part of your code base), suggest you use signals[1].
Hmm. Triggers have advantages over application-level code where they can
be used.
On 12/8/12 5:37 AM, Derek wrote:
Rather than use a trigger (which is DB-specific and also hard to debug
because not part of your code base), suggest you use signals[1].
Hmm. Triggers have advantages over application-level code where they can
be used. They are likely more efficient (no data needs
Rather than use a trigger (which is DB-specific and also hard to debug
because not part of your code base), suggest you use signals[1].
Derek
[1] https://docs.djangoproject.com/en/dev/topics/signals/
On Saturday, 8 December 2012 04:27:50 UTC+2, Chris Cogdon wrote:
>
> It's a simple performance
It's a simple performance vs storage question.
Storing a calculatable field also risks it getting out of sync with
reality, but if you're doing the query on that _so_ much, then its usualyl
worth it.
Also, with the right database and a trigger, that's something the database
can ensure for you.
Hi,
I have a "ranking" field for an item that returns an integer between 1 to
10 based on a number of criteria of each item.
My question is - what are the pros and cons of using a model method to
return this, versus overriding the save() method and saving it directly
into a normal IntegerField
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.
/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
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
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
I got some help on the Django IRC channel:
The anwser is that django save m2m relationship in the admin by
calling 'clear' on it, then setting it. I means that the form destroy
any attached data to the object then add the ones in you entered in
the admin.
It works outside the admin because we don
I overrided the save method of one of my model to it sync its sites
with its parent sites:
def save(self, *args, **kwargs):
ret = models.Model.save(self, *args, **kwargs)
if self.id:
for site in self.parent.sites.all():
self.sites.add(site.id)
This code work, except
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,
Yeah, I realize this now hah. Instead I am now passing request into a
ModelForm for what I need. Basically I have a comment system, and on
each comment post I wanted to run it through Akismet, which required
the IP and User Agent. So I just passed request into my form.save()
method on comment adds.
> Hey everyone. I'm trying to access the request object while overriding
> the save or tapping into the post_save on a model. I need request info
> when someone posts a comment. But I don't just want to handle this in
> my view, I would like it to be cleaner than that, so that
> functionality would
Hey everyone. I'm trying to access the request object while overriding
the save or tapping into the post_save on a model. I need request info
when someone posts a comment. But I don't just want to handle this in
my view, I would like it to be cleaner than that, so that
functionality would remain ev
On Thu, Sep 24, 2009, Daniele Procida wrote:
>>So, given a obj = Referrer("foo"), updating its many-to-many field can
>>happen only after obj.save() returns (this is documented in
>>http://www.djangoproject.com/documentation/models/many_to_many/ ).
>>
>>If you are not able to call obj.save() and
On Thu, Sep 24, 2009, mrts wrote:
>So, given a obj = Referrer("foo"), updating its many-to-many field can
>happen only after obj.save() returns (this is documented in
>http://www.djangoproject.com/documentation/models/many_to_many/ ).
>
>If you are not able to call obj.save() and then manually u
On Sep 24, 12:52 am, "Daniele Procida"
wrote:
> Don't I need to run some sort of save for those? Otherwise, what happens
> to the attributes once I have set them?
Sorry, I responded too hastily and erroneously. Here's the proper,
longer explanation.
Assume the following models:
class Referee(m
On Wed, Sep 23, 2009, mrts wrote:
>> So, obviously I need another stage, to save the many-to-many relations
>> once theo bject is saved.
>
>Call super(Event, self).save(), then update the many-to-many
>relations.
Don't I need to run some sort of save for those? Otherwise, what happens
to the at
On Sep 23, 10:40 am, "Daniele Procida"
wrote:
> So, obviously I need another stage, to save the many-to-many relations
> once theo bject is saved.
Call super(Event, self).save(), then update the many-to-many
relations.
--~--~-~--~~~---~--~~
You received this mess
My model has a save() override, in which a number of attributes (which
are ManyToManyFields) need to get their values from the object's parent:
def save(self):
if self.parent:
attribute_list = ['publishing_destinations',
'registration_enquiries', 'speakers', 'related_peopl
Thanks Karen! I've been stumped on this for quite a while and really
appreciate your help, you're the best.
Cheers,
J
On Aug 10, 5:16 pm, Karen Tracey wrote:
> On Mon, Aug 10, 2009 at 3:07 PM, neridaj wrote:
>
> > when I do this it just creates a unix executable file of the same name
> > sele
On Mon, Aug 10, 2009 at 3:07 PM, neridaj wrote:
>
> when I do this it just creates a unix executable file of the same name
> selected from the drop down menu of users, i.e., if a user named
> testuser24 is selected from the user menu and there is a folder named
> testuser24 a unix executable is c
when I do this it just creates a unix executable file of the same name
selected from the drop down menu of users, i.e., if a user named
testuser24 is selected from the user menu and there is a folder named
testuser24 a unix executable is created named testuser24_. Does this
have something to do wi
On Sun, Aug 9, 2009 at 10:23 PM, neridaj wrote:
>
> It was suggested to me in an earlier post, to override save, and
> though I've read the documentation for upload_to before I guess I
> don't quite know how to implement it without an example. Due to my
> lack of experience I don't know how to ad
= os.path.join(settings.MEDIA_ROOT, 'listings',
self.user.username)
return user_dir_path
zipfile = models.FileField(upload_to=overwrite_upload_to(self,
name))
On Aug 9, 5:24 pm, Karen Tracey wrote:
> On Sun, Aug 9, 2009 at 8:16 PM, neri...@gmail.com wrote:
>
> > Hello,
On Sun, Aug 9, 2009 at 8:16 PM, neri...@gmail.com wrote:
>
> Hello,
>
> I'm having trouble overriding save() to change the upload_to attribute
> of a FileField object. I would like the upload_to attribute to change
> depending on which user is selected from the se
Hello,
I'm having trouble overriding save() to change the upload_to attribute
of a FileField object. I would like the upload_to attribute to change
depending on which user is selected from the select menu i.e., if user
testuser24 is selected the upload_to would change to
upload_to=
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
On Sep 4, 7:18 am, canburak <[EMAIL PROTECTED]> wrote:
> I have a problem on overriding the save() method.
> my new save is:
> class ClassName:
> def save(self):
> self.title = self.title.title()
> super(ClassName, self).save()
>
> when admin site uses this save(), I get the non-unique
What is self.title and self.title.title() ?
On 4 , 15:18, canburak <[EMAIL PROTECTED]> wrote:
> I have a problem on overriding the save() method.
> my new save is:
> class ClassName:
> def save(self):
> self.title = self.title.title()
> super(ClassName, self).save()
>
> when admin s
I have a problem on overriding the save() method.
my new save is:
class ClassName:
def save(self):
self.title = self.title.title()
super(ClassName, self).save()
when admin site uses this save(), I get the non-unique exception at
django/python level but I hope to see a red box in the adm
There is no solution, really - the links can't be added until the
model is saved, so they will not be available in save()
The only way you could work with m2m data is in a custom view, since
then you can connect them and do whatever.
--~--~-~--~~~---~--~~
You rec
I've had a similar problem in the past and have been unable to solve it.
I'm not sure that there is any simple solution.
-Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this gr
Also tried grabbing the post save signal...
the object that is sent with the signal is the old object, eg. the
object before updates.
as this is the post_save signal I tried loading the object again from
database and there also it is the old version.
Any thoughts about how I can get the updated
Hi
I'm trying to override the save method in the django admin interface,
I have no problems getting values for the normal fields but when I try
to access the values for multiple choice fields (many to many fields),
I only get the last values, not the new values selected. This goes for
both callin
Hello,
hope this will help:
http://groups.google.com/group/django-users/browse_frm/thread/ad819fa9daa9e51/e514ba4c416e1b0a?lnk=gst&q=Sandro&rnum=2#e514ba4c416e1b0a
Good luck,
Alex.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
Hi django users,
I am currently trying to make a model `Image` create a thumbnail on
save(). I know that there is a third party ImageWithThumbField, but (a)
I'd like to make and (b) I am curious how my problem would be solved.
As mentioned in the topic, I override the save method of my model. On
Thank you. I'll give that a try.
--~--~-~--~~~---~--~~
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 t
On 6/19/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
...
> Now, if I set up a join table (a DocumentRecipient model with Document
> and Recipient as foreign keys) and override the DocumentRecipient
> save() function to send the email, that works, but that seems like a
> clunky way to do things
I'm writing a simple app with a Document model and a Recipient model,
with a ManyToMany relationship between the two. When the document is
saved, I'd like all related recipients to be sent an email. I've tried
overriding the save() method of my Document object, but it cannot
access the related r
82 matches
Mail list logo