Here is where Django can help you out a lot.
Mezzanine, being built on top of Django, have this thing called signals.
Signals allows you to "hook" into behaviour.
All models in Django comes with some pre existing signals, post_save is the
one you are after. These signals can be listened to anywhere as long as
they are being loaded by an "app" in the INSTALLED_APPS list.
I usually do this by writing a new file I call receivers.py in one of my
apps and then make sure that receivers.py is imported by importing it in
__init__.py
in __init__.py
import myapp.receivers
in receivers.py
from django.db.models.signals import post_save, post_delete
"""
You have to import Mezzanine's blog model here as well as that is the
one you want to listen to
"""
@receiver(post_save, sender=Blog)def mkdir(sender, instance, *args,
**kwargs): """
Create your directory here. You can access the model instance
through instance.
ex: instance.title or instance.slug
"""
So there you have it. That is a fairly simple way of making sure
something happens after something else happens without having to go
into other people's files and make changes.
I included post_delete for you there as well, since you likely will
want to delete directories when a Blog is removed.
Hope this helps :)
On Sun, Oct 26, 2014 at 8:30 PM, David Mendez <[email protected]> wrote:
> Hi everyone!
> I 'm trying to figure how to inject a mkdir command (blogpost title as
> folder name) rigth after the add new blogpost.
> button pressed event ,in the mezzanine form admin
> .
> Steps:
> 1° create new blogpost.
> 2° send mkdir "blogpost.title" but where ? any help ?
> Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.