Tuesday, July 25, 2017

Re: Adding code when pressing one of admin's save buttons

On 25/07/2017 9:29 PM, ron_w_add via Django users wrote:
>
> I am using Django's admin interface to create new records. A record
> includes (amongst other fields) the date and time that a photo was
> taken. These fields will be filled into the database when either the
> 'Save and add another', 'Save and continue editing' or the 'Save'
> buttons are pressed (i.e. these details will be read from the image
> file and entered into the database rather than the administrator doing
> this manually).
>
> How can I added the extra code required to add the date and time when
> I press one of these buttons? Some example code would be appreciated.
>

class MyModel(models.Model):

...
photodatetime = models.DateTimeField()
...

def save(self, *args, **kwargs):
photodatetime = self.getphotoinfo()
super(MyModel, self).save(*args, **kwargs)

def getphotoinfo(self):
...




> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/63559d9c-15c6-4ce1-b477-8e24b030ce0c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/63559d9c-15c6-4ce1-b477-8e24b030ce0c%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/990bc5c5-a65d-d729-b895-6eaf0293d139%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment