django-signals

Raise 404 and continue the URL chain

匆匆过客 提交于 2019-12-06 16:36:51
问题 I've got a URLs pattern like this: urlpatterns = ( url(r'^$', list_titles, name='list'), url(r'^(?P<tag>[a-z\-0-9]+?)/$', list_titles, name='filtered-list'), url(r'^(?P<title>\S+?)/$', show_title, name='title'), ) The filtered-list and title match the same things. If there is an available list of things matching the tag in filtered-list , I want list_titles to fire off. But if there isn't a matching tag , I want to bubble that back to the URL processor so show_title fires off. If there's no

Django signals - kwargs['update_fields'] is always None on model update via django admin

我只是一个虾纸丫 提交于 2019-12-06 12:52:46
问题 I have a signal inside my django app where I would like to check if a certain field in my model has been updated, so I can then proceed and do something. My model looks like this... class Product(models.Model): name = models.CharField(max_length=100) price = models.PositiveIntegerField() tax_rate = models.PositiveIntegerField() display_price = models.PositiveInteger() inputed_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.SET_NULL) updated_by = models

Send an e-mail notification when a Django CharField is modified via the admin site

孤者浪人 提交于 2019-12-06 11:52:14
问题 I have a CharField that is normally empty. I want to send out an e-mail notification to all managers (using mail_managers ) when the field is set to a non-empty value. Changes to this field should only happen via the admin site. I assumed this might be something I could do via signals but I do not see an appropriate signal listed in the documentation. Any ideas? 回答1: You will need to add some history to the field if you don't want updates if the field is changed again but just adding a save

Django refresh page if change data by other user

柔情痞子 提交于 2019-12-06 05:30:29
I have a test django app. In one page the test show the same question to all users. I'd like that when a user answers correctly, send a signal to other active user's browser to refresh to the next question. I have been learning about signals in django I learning work with them but I don't now how send the "refresh signal" to client browser. I think that it can do with a javascript code that check if a certain value (actual question) change and if change reload the page but I don't know this language and the information that I find was confused. Can anybody help me? Many Thanks. There is no

Django: determine which user is deleting when using post_delete signal

杀马特。学长 韩版系。学妹 提交于 2019-12-06 02:03:49
问题 I want admins to be notified when certain objects are deleted but I also want to determine which user is performing the delete. Is it possible? This is the code: # models.py # signal to notify admins when nodes are deleted from django.db.models.signals import post_delete from settings import DEBUG def notify_on_delete(sender, instance, using, **kwargs): ''' Notify admins when nodes are deleted. Only for production use ''' if DEBUG: #return False pass # prepare context context = { 'node':

Use signals in Django 1.9

血红的双手。 提交于 2019-12-05 21:45:00
In Django 1.8, I was able to do the following with my signals, and all was well: __init__.py: from .signals import * signals.py: @receiver(pre_save, sender=Comment) def process_hashtags(sender, instance, **kwargs): html = [] for word in instance.hashtag_field.value_to_string(instance).split(): if word.startswith('#'): word = render_to_string('hashtags/_link.html', {'hashtag': word.lower()[1:]}) html.append(word) instance.hashtag_enabled_text = ' '.join(html) In Django 1.9, I get this error: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. I know it's coming from the __init__

Apps aren't loaded yet. with signals

不羁的心 提交于 2019-12-05 20:01:14
问题 I have an app not ready style error when i use signal. I think this is due to the User auth in the profile model , from what i've see using google there is some issue with the user auth. i think that the error is here : class Profile_User(models.Model): user = models.OneToOneField(User, null=True) but i have no clue on how to solve it. The model with the signal : from django.db import models from Modif_Box.models import Modif_Box_User from Profile.models import Profile_User from Post.models

Redefinition of AppConfig.ready()

ぃ、小莉子 提交于 2019-12-05 18:17:14
Django 1.9. Trying to learn signals. In the documentation for AppConfig.ready() it is said that "Subclasses can override this method to perform initialization tasks such as registering signals." ( https://docs.djangoproject.com/en/1.9/ref/applications/#django.apps.AppConfig.ready ). some_app/apps.py class SomeAppConfig(AppConfig): name = 'some_app' def ready(self): print("Redefined ready method in some_app") demo_signals/settings.py INSTALLED_APPS = [ ... "some_app.apps.SomeAppConfig", ] python manage.py runserver Redefined ready method in some_app Redefined ready method in some_app Performing

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

你离开我真会死。 提交于 2019-12-05 16:19:46
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 = True).save() which, from what i read, was all i thought i needed to do to send a message. Well, that and

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

大城市里の小女人 提交于 2019-12-05 10:14:59
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 exist). I've been through this with a debugger but it seems that DRF uses some Django signals magic to do