django-signals

Simple form not validating

泄露秘密 提交于 2020-01-01 17:57:06
问题 I have found here on stackoverflow a method to extend django's built-in authentication using signals. My base User is defined by 'email' and passwords (so no username there). So I'm trying to modify it to my needs, but I'm geting a validation error for my form. Strange thing is that error is connected to the User.email field and I'm getting 'already in use' even though I'm just registering at the moment. Is it trying to save it 2 times or what ? I've discovered it when I was sending

Django Signal via Decorator on Model Method?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 09:22:52
问题 I'm trying to do something like these proposed signal decorators. In addition to having a decorator that connects the decorated method to a signal (with the signal's sender as an argument to the decorator), I would like to use the decorator on class methods. I'd like to use the decorator like so: class ModelA(Model): @connect.post_save(ModelB) @classmethod def observe_model_b_saved(cls, sender, instance, created, **kwargs): # do some stuff pass The decorator is: from django.db.models import

Are django signals also included inside of the transaction.atomic decorator?

不想你离开。 提交于 2020-01-01 08:46:08
问题 I have a model file that uses a post_save signal to create a linked row in another table. In typical fashion, I can create a page from one of my views which is decorated with @transaction.atomic. I would like to know if this decorator will put the creation of the Page object and the SharedPage object in the same transaction. It is not clear from the django docs that signals are a part of this atomic transaction. models.py class Page(models.Model): name = models.CharField(default='My default

Django: Obtaining the absolute URL without access to a request object

折月煮酒 提交于 2020-01-01 01:31:10
问题 I have a model like the one below. When an instance is created, I want to send out an e-mail to an interested party: class TrainStop(models.Model): name = models.CharField(max_length=32) notify_email = models.EmailField(null=True, blank=True) def new_stop_created(sender, instance, created, *args, **kwargs): # Only for new stops if not created or instance.id is None: return # Send the status link if instance.notify_email: send_mail( subject='Stop submitted: %s' % instance.name, message='Check

Have loaddata ignore or disable post_save signals

有些话、适合烂在心里 提交于 2019-12-31 20:34:30
问题 Let's say that you want to setup a test environment for major changes to an application that you have created, and you want to make sure that those data existing in your system will easily load into the new system. Django provides command line facilities for exporting and loading data. Via dumpdata and loaddata python manage.py dumpdata app.Model > Model.json python manage.py loaddata Model.json The documentation, identifies (although not explicitly) that some signals are ignored during this

Django add to cart and cart view error

霸气de小男生 提交于 2019-12-31 07:22:09
问题 I get a 'NoneType' object is not iterable error when I add 1 object to the cart via the scan_to_cart view and want to add a second object. Also I get the same error when I want to view my cart when there are actually objects in it. I could not find a common problem with a solution... Is the python version I work with the issue, or is there a logic or code error? Thanks in advance for suggestions/advice! models: from manageinv.models import Child User = settings.AUTH_USER_MODEL class

Creating a profile model with both an InlineAdmin and a post_save signal in Django

喜夏-厌秋 提交于 2019-12-30 04:11:19
问题 I created a 'profile' model (with a 1-to-1 relationship to the User model) as described on Extending the existing user model. The profile model has an optional many-to-one relationship to another model: class Profile(models.Model): user = models.OneToOneField(User, primary_key=True) account = models.ForeignKey(Account, blank=True, null=True, on_delete=models.SET_NULL) As documented there, I also created an inline admin: class ProfileInline(admin.StackedInline): model = Profile can_delete =

Update the instance after save, using signals by conditionally refference back to the instance in some cases

烈酒焚心 提交于 2019-12-25 16:39:09
问题 I have the following abstract class: class UserStamp(models.Model): created_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, related_name='%(app_label)s_%(class)s_created_by', on_delete=models.CASCADE) updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='%(app_label)s_%(class)s_updated_by', on_delete=models.CASCADE) class Meta: abstract = True I have a custom User that inherits from User. class User(AbstractBaseUser,PermissionsMixin,

Signals working only in shell,not working in admin and frontend

和自甴很熟 提交于 2019-12-25 07:58:30
问题 I am trying to assign some values to a model field after post-save.The model is class Authority(models.Model): no_of_feeds=models.PositiveIntegerField() no_of_rf=models.PositiveIntegerField() no_of_urf=models.PositiveIntegerField() class Feed(models.Model): auth=models.ForeignKey(Authority,blank=False) @receiver(post_save, sender = Feed) def update_model_feed(sender, **kwargs): if kwargs['created']: #only fire when creating new objects kwargs['instance'].auth.no_of_feeds=kwargs['instance']

Django Assign-perm w/ Post-Save Signal

前提是你 提交于 2019-12-25 05:25:16
问题 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