django-signals

Django Assign-perm w/ Post-Save Signal

断了今生、忘了曾经 提交于 2019-12-25 05:25:06
问题 I have a django model named archive that is tied to a group (django auth) by a foreign key. In order for a user to edit something in this archive, they must have permission to do so through django-guardian . I can link an archive with a group as shown in my code below, however, I need to be able to set per-object (archive)-permissions with each group as well. I am seeking to do this using a post_save or post_delete signal (to properly prevent orphan permissions). In other words, here are the

Django connect temporary pre_save signal

此生再无相见时 提交于 2019-12-25 01:55:28
问题 I've been struggling with a Django signal issue for a few days now and would appreciate your thoughts. Scenario : I wish to use a black box method (it's actually the LayerMapping loader in geodjango, but that's not important here) that generates and saves model instances. For some reason, it cannot set one of the fields in my model. Unfortunately, that field cannot be null, so the black box method fails with an IntegrityError. Example code: models.py class MyModel(models.Model): field1 =

Viewflow - start process with Django model post_save signal

≯℡__Kan透↙ 提交于 2019-12-24 20:38:12
问题 Is there a way to start a Viewflow process with Django model post_save signal. I managed to do this: //start viewflow process start = ( flow.StartSignal(post_save, create_dest_flow) .Next(this.approve) ) //create flow function def create_dest_flow(**kwargs): print("Test") pass The "Test" string is printed for every save on any model. If I add activation to the create flow function parameteres I get an error: missing 1 required positional argument: 'activation' . How to start the flow only on

django m2m_changed signal with custom through model

大城市里の小女人 提交于 2019-12-23 12:25:40
问题 I am trying to use the m2m_changed signal to trigger some actions in my application . However, the printout of signaltest() indicates that I am only signalled on pre_clear and post_clear actions. My models.py looks like this: class Entry(models.Model): objects = managers.MyEntryManager() ... fields = models.ManyToManyField('Field', through='EntryField') class Field(models.Model): name = models.CharField(max_length=64, unique=True) description = models.CharField(max_length=256, blank=True)

Storing user's avatar upon registration

萝らか妹 提交于 2019-12-23 03:17:27
问题 I have an extended UserProfile for registering new users. My user_created function connects to signals sent upon registering basic User instance and creates new UserProfile with extended fields from my form. Here's the code : from registration.signals import user_registered from accounts.forms import ExtendedRegistrationForm import accounts from accounts.models import UserProfile def user_created(sender, user, request, **kwargs): form = ExtendedRegistrationForm(request.POST, request.FILES)

Signals registered more than once in django1.1 testserver

烂漫一生 提交于 2019-12-23 02:33:32
问题 I've defined a signal handler function in my models.py file. At the bottom of that file, I use signals.post_save.connect(myhandler, sender=myclass) as recommended in the docs at http://docs.djangoproject.com/en/dev/topics/signals/. However, when I run the test server, simple print-statement debugging shows that the models.py file gets imported twice and (as far as I can tell), this causes my signal handler to get registered twice. This means that every action is handled twice, which is

django how do i send a post_save signal when updating a user?

社会主义新天地 提交于 2019-12-22 08:07:58
问题 having read the docs, https://docs.djangoproject.com/en/dev/topics/signals/ i have created this in my signals.py file: from django.db.models.signals import post_save from django.dispatch import receiver from models import User from models import Story @receiver(post_save, sender=User) def create_initial_story(sender,instance, signal, created, **kwargs): print "helloooo!" if created: Story(user = instance, title = 'Random Stories', description="Random stories", is_closed = False, is_random =

Access to related data of newly created model instance using post_save signal handler

北城余情 提交于 2019-12-22 06:50:43
问题 I need to send an e-mail when new instance of Entry model is created via admin panel. So in models.py I have: class Entry(models.Model): attachments = models.ManyToManyField(to=Attachment, blank=True) #some other fields #... sent = models.BooleanField(editable=False, default=False) Then I'm registring post_save handler function: def send_message(sender, instance, **kwargs): if not instance.sent: #sending an e-mail message containing details about related attachments #... instance.sent = True

Django REST Framework: return 404 (not 400) on POST if related field does not exist?

廉价感情. 提交于 2019-12-22 06:22:48
问题 I'm developing a REST API which takes POST requests from some really brain-dead software which can't PATCH or anything else. The POSTs are to update Model objects which already exist in the database. Specifically, I'm POSTing data for objects with a related field (a SlugRelatedField, as the POSTer knows the 'name' attribute but NOT the 'pk'). However, I need to return a 404 if the POSTer sends data where the 'name' returns nothing on the SlugRelatedField (e.g. the related object does not

Django pre_save signal does not work

江枫思渺然 提交于 2019-12-22 04:04:55
问题 I tested the "pre_save" signal of Django in the following ways, but cannot catch the signal in either of them. $ from django.db.models.signals import pre_save import logging def my_callback(sender, **kwargs): logging.debug("======================================") pre_save.connect(my_callback) Run the above code in manage.py shell: Then I run my website and see models.save() work successfully, but the callback function does not run. Alternatively, I run the above code on shell again and then