aht do you advice me to do ?

Le mardi 12 mai 2020 08:32:04 UTC+1, Uri Kogan a écrit :
>
> From the error message it can be seen that mail_item_count has "country" 
> item which is "CharField".
> But... the signal receiver sets this to instance of  "Pays" object which 
> assumes it is "ForeignKey".
>
> On Tuesday, May 12, 2020 at 9:41:16 AM UTC+3, hajar wrote:
>>
>>
>> class mail_item(models.Model):
>>    #mail_item_fid = 
>> models.OneToOneField(Mail_item_Event,on_delete=models.CASCADE)
>>    Event_cd = models.OneToOneField(Mail_item_Event,on_delete=models.
>> CASCADE,related_name="mail_item_event_cd")
>>    office_Evt_cd = models.ForeignKey(Office,on_delete=models.CASCADE, 
>> related_name='office_Ev')
>>    Date_Evt = models.DateTimeField()
>>    Pays_origine = models.ForeignKey(Pays, on_delete=models.CASCADE ,
>> related_name='paysOrigine')
>>    Pays_destination = models.ForeignKey(Pays,on_delete=models.CASCADE,
>> related_name='paysDestination')
>>    Expediteur_id = models.ForeignKey(Client,on_delete=models.CASCADE,
>> related_name='expedi')
>>    Destinateur_id = models.ForeignKey(Client,on_delete=models.CASCADE,
>> related_name='destin')
>>
>>
>>
>> Le mardi 12 mai 2020 06:43:43 UTC+1, hajar a écrit :
>>>
>>> hello django users , 
>>>
>>> I am trying to update a class using signals , you will understand once 
>>> you see the code below 
>>>
>>> class mail_item_count(models.Model):
>>>    country = models.CharField(max_length=100)
>>>    count = models.IntegerField(default=1)
>>>    
>>>
>>>     def __str__(self):
>>>        return '{}, {}'.format(self.country,self.count)
>>>
>>>     def sum(self):
>>>        a = sum(instance.count for instance in self.objects.all())    
>>>        return a 
>>>
>>>
>>> @receiver(post_save, sender=mail_item)
>>> def update_count(sender, instance, created, **kwargs):
>>>    count_object,_ = 
>>> mail_item_count.objects.get_or_create(country=instance.Pays_origine) 
>>>
>>>     count_object.count = count_object.count + 1
>>>    count_object.save()
>>>
>>> but I am getting this error : 
>>>
>>> *" Tried to update field dashboard.mail_item_count.country with a model 
>>> instance, <Pays: Maroc >. Use a value compatible with CharField. "*
>>>
>>> can you help me out solving it 
>>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/302eac12-0870-45c6-94a5-febc2c0b4112%40googlegroups.com.

Reply via email to